Closed
Description
Before You File a Bug Report Please Confirm You Have Done The Following...
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I have searched for related issues and found none that matched my issue.
- I have read the FAQ and my problem is not listed.
Playground Link
Repro Code
type Tree = [number, Tree[]]
function mapTree(tree: Tree, fn: (n: number) => number): Tree {
const [n, forest] = tree
return [fn(n), forest.map(t => mapTree(t, fn))]
}
ESLint Config
{
"parser": "@typescript-eslint/parser",
"rules": {
"@typescript-eslint/no-unsafe-argument": "error"
}
}
tsconfig
Expected Result
I expect eslint to run without errors.
Actual Result
RangeError: Maximum call stack size exceeded
Occurred while linting /input.tsx:6
Rule: "@typescript-eslint/no-unsafe-argument"
at Mt (https://typescript-eslint.io/sandbox/index.js:111:214546)
at Da (https://typescript-eslint.io/sandbox/index.js:111:215466)
at Da (https://typescript-eslint.io/sandbox/index.js:111:215803)
at Da (https://typescript-eslint.io/sandbox/index.js:111:215803)
at Da (https://typescript-eslint.io/sandbox/index.js:111:215803)
at Da (https://typescript-eslint.io/sandbox/index.js:111:215803)
at Da (https://typescript-eslint.io/sandbox/index.js:111:215803)
at Da (https://typescript-eslint.io/sandbox/index.js:111:215803)
at Da (https://typescript-eslint.io/sandbox/index.js:111:215803)
at Da (https://typescript-eslint.io/sandbox/index.js:111:215803) 6:42 - 6:56
Additional Info
It works if I add an explicit empty array as alternative type:
type Tree = [number, Tree[] | []]
instead of:
type Tree = [number, Tree[]]
See playground example.
type Tree = [number, Tree[] | []]
function mapTree(tree: Tree, fn: (n: number) => number): Tree {
const [n, forest] = tree
return [fn(n), forest.map((t: Tree) => mapTree(t, fn))]
}
Result:
All is ok!