sirisian / ecmascript-types

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

Add destructuring rest object examples #53

Closed sirisian closed 4 years ago

sirisian commented 4 years ago

https://github.com/tc39/proposal-object-rest-spread

Unsure at this point what would be expected. Example:

let { x, ...y } = { x: 1, a: 2, b: 3 };
x; // 1
y; // { a: 2, b: 3 }

So would the user want to be able to do:

let { (x:uint8), ...(y:{ (a:uint8), (b:uint8) }) } = { x: 1, a: 2, b: 3 };
x; // 1 with type uint8
y; // { a: 2, b: 3 } with type uint8

Probably? Good idea to understand the syntax and ensure it doesn't have edge cases.

hax commented 4 years ago

How to rename?

let {x: X} = {x: 1}
X // 1

let {(x: uint8): X} = or let {x: (X: uint8)} = ?

sirisian commented 4 years ago

@hax That's already in the proposal here: https://github.com/sirisian/ecmascript-types#destructuring-assignment-casting The first example you listed would be correct.

Added a new section. https://github.com/sirisian/ecmascript-types#object-rest-destructuring