使用 '<>' 类型断言被禁止,用'as'代替? [英] Type assertion using the '<>' is forbidden,use 'as' instead?
本文介绍了使用 '<>' 类型断言被禁止,用'as'代替?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的规范中有以下测试用例,
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')
});
当我运行它时,我收到以下 lint 错误.
When I run it, I am getting the following lint error.
Type assertion using the '<>' is forbidden, use as instead?
任何人都可以提供帮助.
Can anyone please suggest help.
推荐答案
来自 类型断言.
类型断言
as foo
与 <foo>
最初添加的语法是<foo>
.如下所示:
Originally the syntax that was added was <foo>
. This is demonstrated below:
var foo: any;
var bar = <string> foo; // bar is now of type "string"
但是,当在 JSX 中使用 <foo>
样式断言时,语言语法存在歧义:
However, there is an ambiguity in the language grammar when using <foo>
style assertions in JSX:
var foo = <string>bar;
</string>
因此现在建议您只使用 as foo
以保持一致性.
Therefore it is now recommended that you just use as foo
for consistency.
所以 linter 会警告旧语法.
So the linter warns about the old syntax.
所以在这种情况下,这是新语法:
So in this case, this is in the new syntax:
const url = (http.get as jasmine.spy).calls.args(0)[0]
这篇关于使用 '<>' 类型断言被禁止,用'as'代替?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文