TSLINT:不允许调用“_.isNull”
Posted
技术标签:
【中文标题】TSLINT:不允许调用“_.isNull”【英文标题】:TSLINT: Calls to '_.isNull' are not allowed 【发布时间】:2017-08-30 11:23:37 【问题描述】:我有一个通过以下导入语句使用 lodash 的 Angular 2 项目
import * as _ from 'lodash';
我有一些代码可以访问 lodash isNull 函数
onClick()
var type = _.isNull(id) ? 'new' : 'update';
this.modelChange.fire(this.modelName, type, id: id, name: this.nameControl.value);
TSLint 抛出此警告,我不知道如何解决它。
[39, 20]:不允许调用 '_.isNull'。
这是我的 tslint.json
"rulesDirectory": [
"node_modules/codelyzer"
],
"rules":
"use-input-property-decorator": true,
"use-output-property-decorator": true,
"use-host-property-decorator": true,
"no-attribute-parameter-decorator": true,
"no-input-rename": true,
"no-output-rename": true,
"no-forward-ref" :true,
"no-trailing-whitespace": false,
"use-life-cycle-interface": true,
"use-pipe-transform-interface": true,
"pipe-naming": [true, "camelCase", "my"],
"component-class-suffix": true,
"directive-class-suffix": true,
"ban": [true,
["_", "extend"],
["_", "isNull"],
["_", "isDefined"]
],
"class-name": true,
"comment-format": [false,
"check-space",
"check-lowercase"
],
"curly": true,
"eofline": true,
"forin": true,
"indent": [true, 2],
"interface-name": true,
"jsdoc-format": true,
"label-position": true,
"max-line-length": [false, 140],
"member-ordering": [true,
"public-before-private",
"static-before-instance",
"variables-before-functions"
],
"no-arg": true,
"no-bitwise": true,
"no-console": [true,
"debug",
"info",
"time",
"timeEnd",
"trace"
],
"no-construct": true,
"no-debugger": true,
"no-duplicate-variable": true,
"no-empty": true,
"no-eval": true,
"no-string-literal": false,
"no-switch-case-fall-through": true,
"trailing-comma": true,
"no-trailing-whitespace": true,
"no-unused-expression": true,
"no-use-before-declare": true,
"no-var-requires": true,
"one-line": [true,
"check-open-brace",
"check-catch",
"check-else",
"check-whitespace"
],
"quotemark": [true, "single"],
"radix": true,
"semicolon": true,
"triple-equals": [true, "allow-null-check"],
"typedef": [true,
"callSignature",
"indexSignature",
"parameter",
"propertySignature",
"variableDeclarator"
],
"typedef-whitespace": [true,
["callSignature", "noSpace"],
["catchClause", "noSpace"],
["indexSignature", "space"]
],
"variable-name": false,
"whitespace": [true,
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type"
]
【问题讨论】:
【参考方案1】:检查您的tslint.json
中的ban 规则。 isNull
有一个条目。这就是您收到 linting 警告的原因。
【讨论】:
以上是关于TSLINT:不允许调用“_.isNull”的主要内容,如果未能解决你的问题,请参考以下文章