2
1

プロパティ 'xxx' は型 'never' に存在しません。

Posted at

問題点

TypeScriptの開発中に以下のようなエラーが出ています。
APIから受け取る配列型の指定がないため、Never型になっています。
image.png

解決方法

<script>タグ内に以下のinterfaceを追加してあげます。

interface User {
  id: number;
  name: string;
  email: string;
  address: {
    street: string;
  };
}

userFetchのあとに型を追加してあげます。

const { data: users } = await useFetch<User[]>(
  "https://jsonplaceholder.typicode.com/users"
);

結果

エラーが解消されました。
image.png

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1