Skip to content

[prefer-readonly-parameter-types] Support all readonly built-in types #1758

@stekycz

Description

@stekycz

I would expect the rule to accept all built-in types that are considered read-only. The rules check objects, arrays, and tuples. However, it considers ReadonlySet and ReadonlyMap as objects resulting in false positive.

Repro

{
  "rules": {
    "@typescript-eslint/prefer-readonly-parameter-types": ["error", {
      "checkParameterProperties": true
    }]
  }
}
const x = (data: ReadonlySet<string>): void => {};
const y = (data: ReadonlyMap<string, string>): void => {};

Expected Result

Pass linting because the types used are read-only.

Actual Result

Fails because the type itself has a few methods that are not defined read-only (because they are methods, not properties with function values).

Versions

package version
@typescript-eslint/eslint-plugin 2.24.0
@typescript-eslint/parser 2.24.0
TypeScript 3.8.3
ESLint 6.8.0
node 12.15.0
yarn 1.22.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions