mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
39 lines
984 B
TypeScript
39 lines
984 B
TypeScript
//// [tests/cases/conformance/types/spread/spreadUnion3.ts] ////
|
|
|
|
//// [spreadUnion3.ts]
|
|
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 };
|
|
|
|
|
|
//// [spreadUnion3.js]
|
|
"use strict";
|
|
function f(x) {
|
|
return Object.assign({ y: 123 }, x); // y: string | number
|
|
}
|
|
f(undefined);
|
|
function g(t) {
|
|
let b = Object.assign({}, t);
|
|
let c = b.a; // might not have 'a'
|
|
}
|
|
g();
|
|
g(undefined);
|
|
g(null);
|
|
var x = Object.assign(Object.assign({}, nullAndUndefinedUnion), nullAndUndefinedUnion);
|
|
var y = Object.assign({}, nullAndUndefinedUnion);
|