问题
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