Borek Bernard
Borek Bernard

Reputation: 53251

'as' operator precedence in TypeScript

Do I need to write:

const response = (await got(url)) as got.Response<MyResponseType>;

or is this enough?

const response = await got(url) as got.Response<MyResponseType>;

I could not find a definitive resource on type casting operator precedence.

Upvotes: 4

Views: 345

Answers (1)

pascalpuetz
pascalpuetz

Reputation: 5418

The second example works. Typecasting is always the last step, if not specified otherwise by using parenthesis.

Upvotes: 5

Related Questions