使用'<>'进行断言被禁止,使用"as"代替? [英] Type assertion using the '<>' is forbidden,use 'as' instead?

查看:636
本文介绍了使用'<>'进行断言被禁止,使用"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')
});  

运行它时,出现以下棉绒错误.

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.

因此,lint警告过时的语法.

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]

这篇关于使用'&lt;&gt;'进行断言被禁止,使用"as"代替?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆