Typescript-eslint: [array-type] Support fixing readonly modifier (TS 3.4)

Created on 13 Apr 2019  路  3Comments  路  Source: typescript-eslint/typescript-eslint

Repro

// "typescript/array-type": ["error", "generic"]
const x : readonly number[] = [1];
// fixes to
const x : ReadonlyArray<number> = [1];


// "typescript/array-type": ["error", "array"]
const x : ReadonlyArray<number> = [1]; // should error, but doesn't
// fixes to
const x : readonly number[] = [1];

Versions

| package | version |
| ---------------------------------- | ------- |
| @typescript-eslint/eslint-plugin | 1.6.0 |
| @typescript-eslint/parser | 1.6.0 |
| TypeScript | 3.4.3 |
| ESLint | 5.16.0 |
| node | 10 |

bug eslint-plugin

Most helpful comment

Do you mean you don't want to use readonly T[] and want to instead use ReadonlyArray?

It is correct.

All 3 comments

@bradzacher @JamesHenry I'm working on migration TypeScript repository from TSLint to ESLint and noticed that TSLint/array-type works differently than @typescript-eslint/array-type. TSLint/array-type doesn't handle ReadonlyArray., @typescript-eslint/array-type adds a bunch of changes which we want to avoid for now. What do you think about using ReadonlyArray (can be the default) as an option in order to allow to handle ReadonlyArray and Array separately?

I'm not sure if I understand what you mean..
Do you mean you don't want to use readonly T[] and want to instead use ReadonlyArray<T>?

If what I'm saying is correct - then please open a new feature request issue and we can address it appropriately.


TSLint/array-type doesn't handle ReadonlyArray

That's only because nobody has added support for it.

Do you mean you don't want to use readonly T[] and want to instead use ReadonlyArray?

It is correct.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davidje13 picture davidje13  路  3Comments

kmdrGroch picture kmdrGroch  路  3Comments

valerio-battaglia picture valerio-battaglia  路  3Comments

kimamula picture kimamula  路  3Comments

bradzacher picture bradzacher  路  3Comments