sirisian / ecmascript-types

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

TypedArray views and special syntax. #7

Closed sirisian closed 7 years ago

sirisian commented 8 years ago

I recently added view syntax to the spec. It's special though:

let foo:uint64[] = [1];
let bar = uint32[](foo, 0, 2);

This is the only instance of an array constructor. Is this just a limited feature that's acceptable in the language or could it be expanded. I'm worried someone will point it out as being too special.

So when using custom types like:

let foo:MyType[] = [0, 1, 2];

It's already been defined it would call the constructor for each item. Is there a case where we'd want:

let foo = new MyType[10](10);

I'd read it like "construct 10 objects of MyType and construct each object with the parameter 10. Is this too niche?

Also the TypedArray example was an empty array so a better comparison is:

let foo = new MyType[](10);

foo.push(); // Construct an object MyType(10) by default? Seems niche.

Any thoughts on if this line of thought could create actually useful feature or is just pointless?

sirisian commented 7 years ago

This is implemented in the spec except the .push thing since it makes no sense to include it in this spec.