我的规范中有以下测试用例,
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?
任何人都可以请建议帮助。
我的规范中有以下测试用例,
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?
任何人都可以请建议帮助。
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]