Skip to content

[prefer-readonly-parameter-types] extending ReadonlyArray gives false positive #1789

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

Closed
ckknight opened this issue Mar 23, 2020 · 1 comment · Fixed by #1791
Closed

[prefer-readonly-parameter-types] extending ReadonlyArray gives false positive #1789

ckknight opened this issue Mar 23, 2020 · 1 comment · Fixed by #1791
Labels
documentation Documentation ("docs") that needs adding/updating package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@ckknight
Copy link

Repro

{
  "rules": {
    "@typescript-eslint/prefer-readonly-parameter-types": "error"
  }
}
interface CustomArrayType extends ReadonlyArray<string> {
  readonly prop: string;
}
function custom1(arg: CustomArrayType) {}

Expected Result
No error

Actual Result
Parameter should be a read only type

Additional Info
This is the example within https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-readonly-parameter-types.md

Versions

package version
@typescript-eslint/eslint-plugin 2.25.0
@typescript-eslint/parser 2.25.0
TypeScript 3.8.3
ESLint 6.8.0
node 12.16.1
npm 6.13.4
@ckknight ckknight added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Mar 23, 2020
@bradzacher
Copy link
Member

sorry, the examples are incorrect, the tests are correct:

`
interface Test extends ReadonlyArray<string> {
readonly property: boolean
}
function foo(arg: Readonly<Test>) {}
`,

Because the type extends an array type, it is no longer classified as an array by TS.
Which means it's just treated as a plain old JS object.

@bradzacher bradzacher added documentation Documentation ("docs") that needs adding/updating and removed triage Waiting for team members to take a look labels Mar 23, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Documentation ("docs") that needs adding/updating package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
2 participants