Skip to content

Bug: [no-unsafe-argument] Maximum call stack size exceeded for recursive types #7298

Closed
@mxgr7

Description

@mxgr7

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

https://typescript-eslint.io/play/#ts=5.1.6&fileType=.tsx&code=FAFwngDgpgBAKgJyrAvDA2gOwK4FsBGUCANPElOgLqXDABm2mAxiAJYD2mMuAhhIsgAUIcgC4yyUnUzjBMmDgJEAlDBQA%2BBXkIJl4gbADewGDCacAziAyYp7JFcpqYI5CZhIQ2BF3TS5ynYOIAB0vBCCwvrkqhrcfAbCUpjKyjQAvkA&eslintrc=N4KABGBEAOCGBOBnApvSAuKABALgT2mUQGN4BLaHAWiIBsyA7HAejiVUgBpwp4BXWkQxhQECJFwEipCtTqMWDAPZU%2BDRLABmyKggDmfALbImwyKnhK0PAL4gbQA&tsconfig=N4XyA&tokens=false

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions