Type string trivially inferred from a string literal, remove type annotation (no-inferrable-types)
2017-09-30 00:00
218 查看
TypeScript代码:
会导致tslint报错:
Type string trivially inferred from a string literal, remove type annotation (no-inferrable-types)。
tslint觉得自己根据右边的"www.baidu.com"判断出requestUrl的类型是string,所以,认为再写string是多此一举。
解决方法:tslint.json添加"ignore-properties"。不推断类的属性(字段)。
-------------------------------------------------
TypeScript无类型推断配置。
译文:
合理
编译器容易推断的显式类型使得代码更加冗长。
标记:
TS独有已经固定
例子:
样板:
private goY : string = 'www.baidu.com';
会导致tslint报错:
Type string trivially inferred from a string literal, remove type annotation (no-inferrable-types)。
tslint觉得自己根据右边的"www.baidu.com"判断出requestUrl的类型是string,所以,认为再写string是多此一举。
解决方法:tslint.json添加"ignore-properties"。不推断类的属性(字段)。
"no-inferrable-types": [ true, "ignore-params", "ignore-properties" ],
-------------------------------------------------
TypeScript无类型推断配置。
译文:
规则:无推断类型
不允许对初始化为数字,字符串或布尔值的变量或参数进行显式类型声明。合理
编译器容易推断的显式类型使得代码更加冗长。
标记:
TS独有已经固定
配置
可以提供两个参数:ignore-params允许为函数参数指定不可推出的类型注释。当与
typedef规则组合时,这可以很有用。
ignore-properties允许为类属性指定不可推出的类型注释。
例子:
"no-inferrable-types": true "no-inferrable-types": [true, "ignore-params"] "no-inferrable-types": [true, "ignore-params", "ignore-properties"]
样板:
{ "type": "array", "items": { "type": "string", "enum": [ "ignore-params", "ignore-properties" ] }, "minLength": 0, "maxLength": 2 }
相关文章推荐
- Type string trivially inferred from a string literal, remove type annotation (no-inferrable-types)
- web项目整合MongoDb出现No converter found capable of converting from org.bson.types.ObjectId to type Long异常
- cocos2dx android版本移植时的Error format not a string literal and no format arguments解决方案
- C++,如何输出string类型的数据(报错:no operator defined which takes a right-hand operand of type 'class std::bas)
- Spring.net Could not load type from string value
- Failed to merge incompatible data types StringType and BinaryType
- snprintf()使用Warn提示:warning: format not a string literal and no format arguments
- SSH出错---The method getRealPath(String) from the type ServletRequest is deprecated request.getRealPath("")
- Type mismatch: cannot convert from Test to Annotation
- Incompatible pointer types returning 'NSArray *' from a function with result type 'xxx *'
- Cocos2dx跨平台编译Android错误:format not a string literal and no format arguments [-Werror=format-security]
- format not a string literal and no format arguments
- Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property 'xxx': no matching editors or conversion strategy found
- ReactJs 报错 Element type is invalid: expected a string (from built-in components) or a class/function (for composite components) but got: undefined. Check the render method of `Me`.
- SpringMVC Failed to convert from type java.lang.String to type java.util.Date for value '2014-12-02'
- The method contains(CharSequence) from the type String refers to the missing type CharSequence错误解决方法
- format not a string literal and no format arguments [-Werror=format-security]
- Type mismatch: cannot convert from Test to Annotation
- Failed to convert from type java.lang.String to type java.util.Date for value………解决办法
- from String value ('{}'); no single-String constructor/factory