Luc*_*oke 1 typescript ionic2 angular
这是代码:
var x = {};
x.test = 'abc';
Run Code Online (Sandbox Code Playgroud)
获取打字稿编译器错误:
TS2339:类型“{}”上不存在属性“test”。
我想禁止这种警告的对象的文字,我想这将suppressExcessPropertyErrors成为tsconfig.json应该解决这个问题。
配置:
{
"compilerOptions": {
"suppressExcessPropertyErrors": true
},
...
}
Run Code Online (Sandbox Code Playgroud)
但没有任何改变..编译器仍然显示错误。
谢谢你的任何提示;)
我想将suppressExcessPropertyErrors 放入tsconfig.json 应该可以解决这个问题。
不。它会抑制对象构造中的多余属性,例如
var x = {};
x = {test:'abc'};
Run Code Online (Sandbox Code Playgroud)
我想抑制对象文字的这个警告
你可以使用any类型做任何你想做的事情,例如
var x:any = {};
x.test = 'abc';
Run Code Online (Sandbox Code Playgroud)
这称为惰性对象初始化,此处介绍了处理它的模式:https : //basarat.gitbooks.io/typescript/content/docs/tips/lazyObjectLiteralInitialization.html
| 归档时间: |
|
| 查看次数: |
4986 次 |
| 最近记录: |