実現したいこと
今百人一首の下の句を覚えるアプリを作成しています。
純粋にクイズをやる部分と、復習パート(クイズ部分に☆マークを付け、それが押下されたものを復習パートに持っていく)に別れています。
発生している問題・分からないこと
復習対象にマークを付ける機能、そして、マークの表示更新のincludesのところでエラーが発生しています。
エラーメッセージ
error
1app.ts:20:35 - error TS2550: Property 'includes' does not exist on type 'number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2016' or later. 220 isFavorite: favorites.includes(k.number) // お気に入りフラグを設定 3app.ts:101:19 - error TS2550: Property 'includes' does not exist on type 'number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2016' or later. 4101 if (favorites.includes(currentKaruta.number)) {
該当のソースコード
TypeScript
1// ページ読み込み時にJSONデータを取得 2fetch('karuta.json') 3 .then(response => response.json()) 4 .then((data: Karuta[]) => { 5 karutaList = data.map(k => ({ 6 ...k, 7 isFavorite: favorites.includes(k.number) // お気に入りフラグを設定 8 })); 9 nextQuestion(); 10 }); 11 12function updateFavoriteButton() { 13 const favoriteButton = document.getElementById('favoriteButton')!; 14 if (!currentKaruta) return; 15 16 if (favorites.includes(currentKaruta.number)) { 17 favoriteButton.textContent = '★'; 18 favoriteButton.style.color = 'gold'; 19 } else { 20 favoriteButton.textContent = '☆'; 21 favoriteButton.style.color = 'gray'; 22 } 23}
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
moduleとlibのバージョンの問題であることが読み取れたため、tsconfig.jsonをES2020に修正していますが、それでもエラーが出続けます。
それともmoduleとlibのバージョンの問題ではないのでしょうか?どなたかお知恵を拝借願いたいです。
補足
TypeScriptのバージョン
- 5.8.2
Node.jsのバージョン
- 18.14.0
tsconfig.jsonの内容と、入力したコマンドも示していただけませんでしょうか。
jsonの内容は以下です(コメントアウトされているものは除いて掲載しています)
```json
{
"compilerOptions": {
"target": "ES2020", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"lib": [
"ES2020",
"DOM"
],
"module": "ESNext", /* Specify what module code is generated. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
/* Type Checking */
"strict": true, /* Enable all strict type-checking options. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
}
```
また入力コマンドは `tsc app.ts`です。

回答1件
あなたの回答
tips
プレビュー