Tslint: Rule array-type does not play well with TS 3.4.1 readonly keyword

Created on 8 Apr 2019  ยท  3Comments  ยท  Source: palantir/tslint

Bug Report

  • __TSLint version__: 5.15
  • __TypeScript version__: 3.4.1
  • __Running TSLint via__: VSCode

TypeScript code being linted

// old (pre TS 3.4.0)
type Matrix<T> = ReadonlyArray<ReadonlyArray<T>>;
// new (TS 3.4.0)
type Matrix<T> = readonly (readonly T[])[];
// code snippet

with tslint.yaml configuration:

extends:
- tslint:recommended

which uses rule array-type with option array-simple.

TSLint fails to lint second line, but TypeScript enforces usage of "readonly" before simple array types. The following line would not pass TSC:

type Matrix<T> = readonly Array<readonly T[]>;

Actual behavior

TSLint fails to lint second line.

Expected behavior

TSLint lets pass the syntax as this is the only way to make complex array types read-only (without adding an intermetiate typedef for inner elements).

P2 Bug ๐ŸŒน R.I.P. ๐ŸŒน

Most helpful comment

BTW even simpler example

type T1 = ReadonlyArray<number | string>;
type T2 = readonly (number | string)[]; // TSLint fails

All 3 comments

BTW even simpler example

type T1 = ReadonlyArray<number | string>;
type T2 = readonly (number | string)[]; // TSLint fails

๐Ÿ’€ _It's time!_ ๐Ÿ’€

TSLint is deprecated and no longer accepting pull requests other than security fixes. See #4534. โ˜ ๏ธ
We recommend you instead use typescript-eslint to lint your TypeScript code with ESLint. โœ…

๐Ÿ‘‹ It was a pleasure open sourcing with you!

๐Ÿค– Beep boop! ๐Ÿ‘‰ TSLint is deprecated ๐Ÿ‘ˆ _(#4534)_ and you should switch to typescript-eslint! ๐Ÿค–

๐Ÿ”’ This issue is being locked to prevent further unnecessary discussions. Thank you! ๐Ÿ‘‹

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zewa666 picture zewa666  ยท  3Comments

dashmug picture dashmug  ยท  3Comments

ghost picture ghost  ยท  3Comments

allbto picture allbto  ยท  3Comments

jacob-robertson picture jacob-robertson  ยท  3Comments