Closed
Description
A following valid destructuring assignment always occurs a TypeError.
// typescript
var {x: {y}}: {x?: {y?}} = {}; // should be a compile error
// emit
var y = {}.x.y; // TypeError: (intermediate value).x is undefined
// javascript on firefox
var {x:{y}} = {}; // TypeError: can't convert undefined to object
Destructuring assignment should constrain type declarations.
// expects
var {x: {y}}: {x: {y}} = {x: {y: 0}}; // ok
var {x: {y}}: {x?: {y?}} = {}; // error
var {x: {y = 0}}: {x?: {y?}} = {}; // error
var {x: {y} = {y: 0}}: {x?: {y?}} = {}; // error
var {x: {y = 0} = {}}: {x?: {y?}} = {}; // error
var {x: {y = 0} = {y: 0}}: {x?: {y?}} = {}; // ok
Destructuring assignments violate a following type constraint.
var options: {x?: {y?}};
var required: {x: {y}} = options; // compile error, but destructuring assignments are not.
var {x: {y}}: {x?: {y?}} = {}; // should be a compile error
Destructuring assignments have a own implicit type but TypeScript breaks it type improperly.