LoginSignup
1
0

More than 1 year has passed since last update.

プロパティ 'data' は型 'GraphQLResult<object> | Observable<object>' に存在しません。ts(2339)の対処メモ

Posted at

TypeScript & Amplifyで起きるエラーの対処メモ

Amplifyで作成した開発環境でGraphQLのスキーマを読み込もうとしたらこんなエラーが

 async function fetchNotes() {
    const apiData = await API.graphql({ query: listNotes });
    setNotes(apiData.data.listNotes.items);
  }
プロパティ 'data' は型 'GraphQLResult<object> | Observable<object>' に存在しません。
プロパティ 'data' は型 'Observable<object>' に存在しません。ts(2339)

TypeScriptの型定義がされてないため、エラーが起きています。

解決策

// @ts-ignore

を加えると、エラーが回避されます。

例:

const apiData = await API.graphql({ query: listNotes });
// @ts-ignore
setNotes(apiData.data.listNotes.items);

これでエラーが回避されました。

他の解決策

// @ts-ignore

を使うと一括で型エラーを回避してくれますが、型無効化というのは抵抗あるので他の解決策も探してみます。

参考:
https://higelog.brassworks.jp/2824
https://github.com/aws-amplify/amplify-js/issues/4257

1
0
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
1
0