Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[prefer-readonly-parameter-types] Emits an error on a recursive type #1665

Labels
bug Something isn't working has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@Ailrun
Copy link

Ailrun commented Mar 3, 2020

Repro

{
  "rules": {
    "@typescript-eslint/prefer-readonly-parameter-types": ["warn"]
  }
}
interface Tree {
  readonly value: number;
  readonly children: readonly Tree[];
}

export const sum = (x: Tree): number => {
  return x.children.map(sum).reduce((acc, s) => acc + s, x.value);
};

Expected Result

Being checked without any exception.

Actual Result

Emitting an error like the following.

RangeError: Maximum call stack size exceeded
Occurred while linting /<path>/example.tsx:6
    at getPropertyOfType (/<path>/node_modules/tsutils/util/type.js:1:1)
    at /<path>/node_modules/tsutils/util/type.js:173:22
    at someTypePart (/<path>/node_modules/tsutils/util/type.js:100:52)
    at isReadonlyPropertyIntersection (/<path>/node_modules/tsutils/util/type.js:172:12)
    at Object.isPropertyReadonlyInType (/<path>/node_modules/tsutils/util/type.js:161:43)
    at isTypeReadonlyObject (/<path>/node_modules/@typescript-eslint/eslint-plugin/dist/util/isTypeReadonly.js:68:28)
    at isTypeReadonly (/<path>/node_modules/@typescript-eslint/eslint-plugin/dist/util/isTypeReadonly.js:116:30)
    at /<path>/node_modules/@typescript-eslint/eslint-plugin/dist/util/isTypeReadonly.js:29:44
    at Array.some (<anonymous>)
    at checkTypeArguments (/<path>/node_modules/@typescript-eslint/eslint-plugin/dist/util/isTypeReadonly.js:29:27)

Additional Info

It looks like there is no recursiveness checking in isTypeReadonly function.

Versions

package version
@typescript-eslint/eslint-plugin 2.22.0
@typescript-eslint/parser 2.22.0
TypeScript 3.8.3
ESLint 6.8.0
node 12.16.0
npm 6.13.7
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.