我想知道是否有一个TSLint规则,我可以禁用以下代码:
var arr = [1, 2];
//the line below should be disallowed
arr.prop1 = "3";
//because arr now has array elements and object properties
Run Code Online (Sandbox Code Playgroud)
我想这个禁止,因为它可以防止arr被具有完全序列化JSON.stringify,因为JSON.stringify将序列arr成[1, 2].
我查看了TSLint规则,但无法为此找到规则.
我为此实现了一条 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
}
}
Run Code Online (Sandbox Code Playgroud)编辑:
它也可以通过设置来实现noImplicitAny: true,对于我的项目来说这不是一个可接受的解决方案,但这是一个简单的解决方案。
| 归档时间: |
|
| 查看次数: |
141 次 |
| 最近记录: |