Any difference between type assertions and the newer `as` operator in TypeScript?

后端 未结 2 541
忘了有多久
忘了有多久 2020-12-01 08:33

Is there any difference between what the TypeScript spec calls a type assertion:

var circle =  createShape(\"circle\");

And t

2条回答
  •  -上瘾入骨i
    2020-12-01 09:18

    From Wiki page: "What's new in TypeScript [1.6]":

    New .tsx file extension and as operator

    TypeScript 1.6 introduces a new .tsx file extension. This extension does two things: it enables JSX inside of TypeScript files, and it makes the new as operator the default way to cast (removing any ambiguity between JSX expressions and the TypeScript prefix cast operator). For example:

    var x =  foo; 
    // is equivalent to:
    var x = foo as any;
    

提交回复
热议问题