0

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.

Julian
  • 33,915
  • 22
  • 119
  • 174
learner
  • 357
  • 1
  • 6
  • 16

1 Answers1

2

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]
Community
  • 1
  • 1
Julian
  • 33,915
  • 22
  • 119
  • 174
  • 1
    FYI to people who come here, wondering why this is the case: see [this issue](https://github.com/microsoft/TypeScript/issues/296) about JSX support problems and the [fix introducing `as`](https://github.com/microsoft/TypeScript/pull/3201). – jcalz Nov 21 '19 at 19:46