Requires using either T[] or Array<T> for arrays (array-type)
Using the same style for array definitions across your codebase makes it easier for your developers to read and understand the types.
Rule Details
This rule aims to standardize usage of array types within your codebase.
Options
The rule accepts an options object with the following properties:
default
- sets the array type expected for mutable cases.readonly
- sets the array type expected for readonly arrays. If this is omitted, then the value fordefault
will be used.
Each property can be set to one of three strings: 'array' | 'generic' | 'array-simple'
.
The default config will enforce that all mutable and readonly arrays use the 'array'
syntax.
"array"
"array"
Always use T[]
or readonly T[]
for all array types.
Incorrect code for "array"
:
Correct code for "array"
:
"generic"
"generic"
Always use Array<T>
or ReadonlyArray<T>
for all array types.
Incorrect code for "generic"
:
Correct code for "generic"
:
"array-simple"
"array-simple"
Use T[]
or readonly T[]
for simple types (i.e. types which are just primitive names or type references). Use Array<T>
or ReadonlyArray<T>
for all other types (union types, intersection types, object types, function types, etc).
Incorrect code for "array-simple"
:
Correct code for "array-simple"
:
Related to
TSLint: array-type
Last updated