sirisian / ecmascript-types

ECMAScript Optional Static Typing Proposal http://sirisian.github.io/ecmascript-types/
453 stars 4 forks source link

Initializer list for array of class instances #14

Closed sirisian closed 7 years ago

sirisian commented 7 years ago
let foo = new Type[] = [(10, 20), (30, 40), 10];

This is very context sensitive. Basically it would notice the array in the assignment and have custom grammar for associating it. There's already this suggested syntax for implicit casting: https://github.com/sirisian/ecmascript-types#implicit-array-cast

I'm making efforts to ensure I'm not adding something in my design where it blocks something obvious in the future. This might need to be in a future spec since it adds weird syntax with parenthesis in arrays. Some other feature might utilize this syntax better. Lambads already kind of take part of the syntax though. [() => {}] type stuff.

sirisian commented 7 years ago

Since [(10, 20), 30] is really just [20, 30] if this has any chance of working it would have to be introduced with the spec: https://github.com/sirisian/ecmascript-types#initializer-list-for-array-of-class-instances