簡體   English   中英

禁止使用“<>”進行類型斷言,請改用“as”?

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

我的規范中有以下測試用例,

it (should create,()=>{
     const url  = (<jasmine.spy> http.get).calls.args(0)[0]
     expect(url).toBe('/api/get')
});  

當我運行它時,我收到以下 lint 錯誤。

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

任何人都可以請提供幫助。

類型斷言

類型斷言

as foo<foo>

最初添加的語法是<foo> 這在下面演示:

 var foo: any; var bar = <string> foo; // bar is now of type "string"

但是,在 JSX 中使用<foo>樣式斷言時,語言語法存在歧義:

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

因此,現在建議您只使用as foo以保持一致性。

所以 linter 會警告舊語法。

所以在這種情況下,這是在新語法中:

const url  = (http.get as jasmine.spy).calls.args(0)[0]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM