dart-archive / ts2dart

ts2dart TypeScript to Dart transpiler
Apache License 2.0
181 stars 62 forks source link

Better support for reified types on literals. #356

Closed mhevery closed 8 years ago

mhevery commented 8 years ago

Given:

var x = <{[k:string]:any}>{};
var y = <string[]>[];

We get:

var x = {} as Map<String, any>;
var y = [] as List<String>;

We want to get:

var x = <String, any>{};
var y = <String>[];
mprobst commented 8 years ago

We translate these as casts as they are casts in TS. Is there anything in particular this breaks?

You could also try:

let x: string[] = [];
mhevery commented 8 years ago

@mprobst Yes, it is a cast, but what I am trying to request is that when we are doing a cast in front of a type literals, then it is not treated as cast, but as reified type. So the current behavior is correct, but we would like to augment it.

BTW, in dart: List<String> x = [] and var x = <String>[] are not the same as one is reified and the other is not. (@vsmenon am I correct?)

mprobst commented 8 years ago

Ah I see, the issue is that you need the type reification inside the container. I'll TAL.

mprobst commented 8 years ago

https://reviews.angular.io/D19

mprobst commented 8 years ago

Fixed, released in v0.7.33 and v0.8.9.

mhevery commented 8 years ago

Love it, thanks