Skip to content

[prefer-readonly-parameter-types] inferred types from third party code make rule painful #2079

Closed
@osdiab

Description

@osdiab

i like the concept of the checker, but it's a pain in the butt in practice if you use third party libraries with typings and hope to use typescript's inference engine, because it errors like crazy.

Repro
Install one of many popular libraries:

yarn add -D ava
# or maybe
yarn add io-ts
{
  "rules": {
    "@typescript-eslint/prefer-readonly-parameter-types": ["error"]
  }
}
// ava - t is not deeply readonly so it errors
// ava's typings don't make this deeply readonly, so it's clear why this would fail
import test from "ava";
test('Stub', (t) => {
	t.is(1, 1);
});

or maybe

import t from io-ts;

// this fails as well - which is extra frustrating since that library even goes to lengths to make things readonly in its typings!
// though I'm guessing it's triggering on the `unknown` values, which isnt feasible to eliminate for this library
// https://github.com/gcanti/io-ts/blob/73d92a08c42dca3d874927d92c8e9ad30d0a11f5/src/index.ts#L28
const parseValidationError = (error: t.ValidationError) => {
  return error;
}

Expected Result

  • that there be configuration options to make the rule more usable for third party typings, some kind of escape hatch that doesn't involve adding an eslint ignore comment over and over again all over my app for inferred types - for example the unknown values in io-ts are essential to its usage, and I trust it, so I'm OK with letting anything from io-ts slide
  • also that there be a little more detail on what exactly was not readonly, since it's sometimes not straightforward to tell from complex types especially from third party libraries what might be wrong, so it's hard for me to make ticket for third parties when it happens

Actual Result
Errors that I can't fix since it's not my typings, besides just ignoring the rule or turning it off

Versions

package version
@typescript-eslint/eslint-plugin 2.29.0
@typescript-eslint/parser 2.29.0
TypeScript 3.9.3
ESLint 6.8.0
node 12.16.3
npm 6.14.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: plugin rule optionNew rule option for an existing eslint-plugin rulegood first issueGood for newcomerslocked 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