TypeScript/tests/cases/conformance/types/spread/spreadUnion3.ts
2017-09-15 10:06:58 -07:00

20 lines
511 B
TypeScript

// @strictNullChecks: true
function f(x: { y: string } | undefined): { y: string } {
return { y: 123, ...x } // y: string | number
}
f(undefined)
function g(t?: { a: number } | null): void {
let b = { ...t };
let c: number = b.a; // might not have 'a'
}
g()
g(undefined)
g(null)
// spreading nothing but null and undefined is not allowed
declare const nullAndUndefinedUnion: null | undefined;
var x = { ...nullAndUndefinedUnion, ...nullAndUndefinedUnion };
var y = { ...nullAndUndefinedUnion };