[英]Type assertion using the '<>' is forbidden,use 'as' instead?
I have the following test case in my spec,我的规范中有以下测试用例,
it (should create,()=>{
const url = (<jasmine.spy> http.get).calls.args(0)[0]
expect(url).toBe('/api/get')
});
When I run it, I am getting the following lint error.当我运行它时,我收到以下 lint 错误。
Type assertion using the '<>' is forbidden, use as instead?
Can anyone please suggest help.任何人都可以请提供帮助。
From Type Assertion .从类型断言。
Type assertions
类型断言
as foo
vs.<foo>
as foo
与<foo>
Originally the syntax that was added was
<foo>
.最初添加的语法是
<foo>
。 This is demonstrated below:这在下面演示:
var foo: any; var bar = <string> foo; // bar is now of type "string"
However, there is an ambiguity in the language grammar when using
<foo>
style assertions in JSX:但是,在 JSX 中使用
<foo>
样式断言时,语言语法存在歧义:var foo = <string>bar; </string>
Therefore it is now recommended that you just use
as foo
for consistency.因此,现在建议您只使用
as foo
以保持一致性。
So the linter warns about the old syntax.所以 linter 会警告旧语法。
So in this case, this is in the new syntax:所以在这种情况下,这是在新语法中:
const url = (http.get as jasmine.spy).calls.args(0)[0]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.