我想知道是否存在TSLint规则,我可以禁用以下代码:
var arr = [1, 2];
//the line below should be disallowed
arr.prop1 = "3";
//because arr now has array elements and object properties
我想禁止此操作,因为它会阻止arr
与JSON.stringify
完全序列化,因为JSON.stringify
会将arr
序列化为[1, 2]
。
我查看了TSLint rules,但无法为此找到规则。
答案 0 :(得分:0)
我为此实现了一个TSLint规则,可以在GitHub和NPM上使用:
可以像这样使用:
npm install no-setting-array-properties-rule --save-dev
安装它。将其添加到tslint.json
,如下所示:
{
"rulesDirectory": [
"../node_modules/no-setting-array-properties-rule/dist/src"
],
"rules": {
"no-setting-array-properties": true
}
}
修改强>
只需设置noImplicitAny: true
即可实现,对于我的项目而言,这不是一个可接受的解决方案,但这很容易解决。