What is the type assertion operator for in TypeScript?

前端 未结 3 2011
野性不改
野性不改 2020-12-20 15:09

The spec doesn\'t say much about where the type assertion operator might be helpful in TypeScript. I didn\'t need it in my code. So I am curious what sort of problems it is

3条回答
  •  独厮守ぢ
    2020-12-20 15:48

    I assume you mean the : [type] notation after the parameters of a function? It doesn't appear to make a difference in the final .js file, but if you run the .ts file through the compiler, it will throw an error if it finds an unexpected input type for any type asserted parameters. Hope that answers your question.

提交回复
热议问题