Encountering an error while attempting to generate a dynamic range of numbers.
Error: Type 'IterableIterator<number>' is not recognized as an array or string type. Use the compiler option '--downlevelIteration' to enable iteration over iterators.
Faced with a similar issue before but unable to find a working solution.
TypeScript and Iterator: Type 'IterableIterator<T>' handling
My current setup includes...
- Initialization command used:
npx create-next-app@latest --ts
class FlexGrid extends React.Component {
range(size: number, startAt = 0) {
return [...Array(size).keys()].map(i => i + startAt);
}
Tried adjusting settings like target: es6
and downlevelIteration: true
, but the error persists.
{
"compilerOptions": {
"target": "es6",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"downlevelIteration": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}