TypeScript casting arrays TypeScript casting arrays typescript typescript

TypeScript casting arrays


There are 4 possible conversion methods in TypeScript for arrays:

let x = []; //any[]let y1 = x as number[];let z1 = x as Array<number>;let y2 = <number[]>x;let z2 = <Array<number>>x;

The as operator's mostly designed for *.tsx files to avoid the syntax ambiguity.


I think the right syntax is:

var rows2 = <Array<any>>rows;

That's how you cast to interface Array<T>


I think this is just a bug - can you log an issue on the CodePlex site?

As a workaround, you can write <Array><any>rows;