mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Spread type:new assignability+simplification tests
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
function f<T, U, V>(t: T, u: U, v: V): void {
|
||||
let o: { ...T, ...U, ...V };
|
||||
let uu: { ...U, ...U};
|
||||
let u: { ...U };
|
||||
let u0: U;
|
||||
uu = u; // ok, multiple spreads are equivalent to a single one
|
||||
u = uu; // ok, multiple spreads are equivalent to a single one
|
||||
u0 = u; // error, might be missing a ton of stuff
|
||||
u = u0; // ok, type has at least all the properties of the spread
|
||||
let uus: { ...U, ...U};
|
||||
let us: { ...U };
|
||||
const same: { ...T, ...U, ...V } = o; // ok
|
||||
uus = us; // ok, multiple spreads are equivalent to a single one
|
||||
us = uus; // ok, multiple spreads are equivalent to a single one
|
||||
us = u; // ok, type has at least all the properties of the spread
|
||||
u = us; // error, might be missing a ton of stuff
|
||||
const reversed: { ...V, ...U, ...T } = o; // error, reversed
|
||||
const reversed2: { ...U, ...T, ...V } = o; // error, U and T are still reversed
|
||||
const missingT: { ...U, ...V } = o; // error, missing T
|
||||
|
||||
@@ -8,10 +8,8 @@ class PrivateOptionalX {
|
||||
class PublicX {
|
||||
public x: number;
|
||||
}
|
||||
let privateOptionalx: PrivateOptionalX;
|
||||
let publicx: PublicX;
|
||||
let o3 = { ...publicx, ...privateOptionalx };
|
||||
let sn: string | number = o3.x; // error, x is private
|
||||
let o3: { ...PublicX, ...PrivateOptionalX };
|
||||
let sn: number = o3.x; // error, x is private
|
||||
let optionalString: { sn?: string };
|
||||
let optionalNumber: { sn?: number };
|
||||
let allOptional: { sn: string | number } = { ...optionalString, ...optionalNumber };
|
||||
@@ -46,6 +44,7 @@ let callableConstructableSpread: { ...PublicX, (n: number): number, new (p: numb
|
||||
callableConstructableSpread(12); // error, no call signature
|
||||
new callableConstructableSpread(12); // error, no construct signature
|
||||
|
||||
let publicx: PublicX;
|
||||
let callableSpread = { ...publicx, ...(n => n + 1) }; // error, can't spread functions
|
||||
|
||||
// { ...U } is not assignable to U
|
||||
|
||||
@@ -3,7 +3,7 @@ interface B1 { b: number };
|
||||
function override<U>(initial: U, override: U): { ...U, ...U } {
|
||||
return { ...initial, ...override };
|
||||
}
|
||||
function update<U>(this: { u: U }, override: U): void {
|
||||
function update<U>(this: { u: { ...U } }, override: U): void {
|
||||
this.u = { ...this.u, ...override };
|
||||
}
|
||||
function mixin<T, U>(one: T, two: U): { ...T, ...U } {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
////interface A1 { [|a|]: number };
|
||||
////interface A1 { [|a|]: string };
|
||||
////interface A2 { [|a|]?: number };
|
||||
////let a12: { ...A1, ...A2 };
|
||||
////a12.[|a|];
|
||||
|
||||
Reference in New Issue
Block a user