Skip to content

Bug: [no-base-to-string] stack overflow with recursive type #10632

Closed
@jtbandes

Description

@jtbandes

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.7.2&fileType=.tsx&code=KYDwDg9gTgLgBDAnmYcBqBDANgV1QXgCg44AfOHAOwBNgAzAS0uGuLLgCMIItgNK25SjgC2HYFEFwAzjChMA5lIAiGGMCkBVJjAAcAQShQMiKZlzAA2gF0pAZTk4AxjADchQqEiwEyVA6hneHw4AG84SwBrYEQALhk5RWt48zw4AF93QjoqFwYISjg6bgAKADcU7DwASjC2JwLpHmAAOiwIBRKAAwAJBjgAElCy9K7q93SgA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1oCMBDZRLXxdk%2BKkwDm6KImjQO0SODABfECqA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

export type Value =
  | undefined
  | boolean
  | number
  | string
  | Date
  | Uint8Array
  | Value[]
  | Struct;

export type Struct = { [key: string]: Value };

function foo(v: Value) {
  console.log(`Hi ${v}`);  // causes rule to crash
}

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/no-base-to-string": "error"
  },
};

tsconfig

{
  "compilerOptions": {
    "strictNullChecks": true
  }
}

Expected Result

No crash

Actual Result

Rule crashes with stack trace like this:

RangeError: Maximum call stack size exceeded
Occurred while linting ...
Rule: "@typescript-eslint/no-base-to-string"
    at getNameOfSymbolAsWritten (.../node_modules/typescript/lib/typescript.js:59075:36)
    at createAccessFromSymbolChain (.../node_modules/typescript/lib/typescript.js:56976:25)
    at symbolToTypeNode (.../node_modules/typescript/lib/typescript.js:56953:26)
    at typeToTypeNodeWorker (.../node_modules/typescript/lib/typescript.js:55397:16)
    at typeToTypeNodeHelper (.../node_modules/typescript/lib/typescript.js:55247:24)
    at mapToTypeNodes (.../node_modules/typescript/lib/typescript.js:56233:28)
    at typeReferenceToTypeNode (.../node_modules/typescript/lib/typescript.js:55913:33)
    at visitAndTransformType (.../node_modules/typescript/lib/typescript.js:55733:24)
    at typeToTypeNodeWorker (.../node_modules/typescript/lib/typescript.js:55402:28)
    at typeToTypeNodeHelper (.../node_modules/typescript/lib/typescript.js:55247:24)

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: 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