Type assertion using the '<>' is forbidden,use 'as' instead?

青春壹個敷衍的年華 提交于 2020-03-16 09:18:37

问题


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.

Type assertion using the '<>' is forbidden, use as instead?

Can anyone please suggest help.


回答1:


From Type Assertion.

Type assertions

as foo vs. <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"

However, there is an ambiguity in the language grammar when using <foo> style assertions in JSX:

var foo = <string>bar;
</string>

Therefore it is now recommended that you just use as foo for consistency.

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]


来源:https://stackoverflow.com/questions/57582716/type-assertion-using-the-is-forbidden-use-as-instead

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!