Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array type using Array<T> is forbidden

My Ttslint throws a warning with this construction (Array type using Array is forbidden. Use T[] instead (array-type) ):

Array<string | null> | null

Is this correct replacement to the previous one?

(string | null)[] | null
like image 370
Avernikoz Avatar asked May 13 '18 18:05

Avernikoz


Video Answer


1 Answers

Yes, that is the behavior that the array-type rule enforces, when it is set to "array":

One of the following arguments must be provided:
* "array" enforces use of T[] for all types T.
* "generic" enforces use of Array for all types T.
* "array-simple" enforces use of T[] if T is a simple type (primitive or type reference).

You can disable the rule for the entire file by creating a tslint.json file in the same folder as the file (or in a parent folder of the file) and writing the following inside it:

"rules": {
    "array-type": false
}

If you want to choose one of the other settings:

"rules": {
    "array-type": [true, "generic"]
}

And, as you've mentioned in your question, the equivalent for:

Array<string | null> | null

is:

(string | null)[] | null
like image 200
Zev Spitz Avatar answered Sep 20 '22 14:09

Zev Spitz