2015-11-03 3 views

答えて

48

違いはas CircleはTSXファイルでは機能しますが、<Circle>はJSX構文と競合します。このため、asが導入されました。

例えば、.tsxファイルに次のコード:

var circle = <Circle> createShape("circle"); 

は、次のエラーになります:

error TS17002: Expected corresponding JSX closing tag for 'Circle'.

しかし、as Circleはうまく動作します。

今からas Circleを使用してください。これは推奨される構文です。 Wiki pageから

13

は: "何が[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 = <any> foo; 
// is equivalent to: 
var x = foo as any; 
関連する問題