TypeScript/tests/cases/conformance/types/literal/literalTypesAndDestructuring.ts
Anders Hejlsberg f8bfc6f5d6
Contextually typed binding element initializers (#35855)
* Binding element initializers contextually typed by parent initializers

* Accept new baselines

* Literal type widening should be last step in inference

* Accept new baselines

* Add tests
2020-01-06 12:53:23 -08:00

23 lines
389 B
TypeScript

// @strict: true
declare let x: { a: 0 | 1 | undefined };
let { a: a1 } = x;
let { a: a2 = 0 } = x;
let { a: a3 = 2 } = x;
let { a: a4 = 2 as const } = x;
let b1 = x.a;
let b2 = x.a ?? 0;
let b3 = x.a ?? 2;
let b4 = x.a ?? 2 as const;
// Repro from #35693
interface Foo {
bar: 'yo' | 'ha' | undefined;
}
let { bar = 'yo' } = {} as Foo;
bar; // "yo" | "ha"