How to use a TypeScript cast with JSX/TSX How to use a TypeScript cast with JSX/TSX typescript typescript

How to use a TypeScript cast with JSX/TSX


The as operator was introduced to TypeScript 1.6 to replace casts in .tsx files, e.g.:

(event.target as HTMLInputElement).value

The TypeScript wiki explains the 1.6 changes:it makes the new as operator the default way to cast (removing any ambiguity between JSX expressions and the TypeScript prefix cast operator)