I have installed tsc globally and running tsc index.ts.
Following is my tsconfig.json file in my root project folder.
{
"compilerOptions": {
"target": "esnext",
"lib": ["dom", "es2017"],
"allowJs": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"module": "es6",
"outDir": "./build",
"moduleResolution": "node",
"resolveJsonModule": true,
"skipLibCheck": true
},
"exclude": ["node_modules", "build"]
}
I am getting the following error when I try to validate whether a number is included in an array.
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.
index.ts:-
const max = 15
const min = 10
let arrayOfRandomNumbers: number[] = []
const getTicket = (): void => {
let randomNumber = null
if (arrayOfRandomNumbers.length === max - min + 1) {
document.querySelector('button').disabled = true
} else {
while (arrayOfRandomNumbers.length < max - min + 1) {
randomNumber = Math.floor(Math.random() * (max - min + 1)) + min
if (!arrayOfRandomNumbers.includes(randomNumber)) {
arrayOfRandomNumbers = [...arrayOfRandomNumbers, randomNumber]
console.log('arrayOfRandomNumbers for:-', arrayOfRandomNumbers)
break
}
}
}
}
getTicket()