我的 Ttslint 会针对此构造发出警告(Array type using Array is forbidden. Use T[] instead (array-type)):
Array<string | null> | null
这是对前一个的正确替换吗?
(string | null)[] | null
最佳答案
是的,这就是 array-type 的行为规则强制执行,当它设置为 "array"
时:
One of the following arguments must be provided:
*"array"
enforces use ofT[]
for all typesT
.
*"generic"
enforces use of Array for all typesT
.
*"array-simple"
enforces use ofT[]
ifT
is a simple type (primitive or type reference).
您可以通过在与文件相同的文件夹(或文件的父文件夹)中创建 tslint.json
文件并在其中写入以下内容来禁用整个文件的规则:
"rules": {
"array-type": false
}
如果您想选择其他设置之一:
"rules": {
"array-type": [true, "generic"]
}
而且,正如您在问题中提到的,等效于:
Array<string | null> | null
是:
(string | null)[] | null
关于javascript - 禁止使用 Array<T> 的数组类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50319251/