diff --git a/tests/baselines/reference/objectSpread.types b/tests/baselines/reference/objectSpread.types index 1a053a22670..86d04eb4588 100644 --- a/tests/baselines/reference/objectSpread.types +++ b/tests/baselines/reference/objectSpread.types @@ -31,7 +31,7 @@ let addAfter: { a: number, b: string, c: boolean } = >c : boolean { ...o, c: false } ->{ ...o, c: false } : { ...{ a: number; b: string; }; c: false; } +>{ ...o, c: false } : { c: false; a: number; b: string; } >o : any >c : boolean >false : false @@ -43,7 +43,7 @@ let addBefore: { a: number, b: string, c: boolean } = >c : boolean { c: false, ...o } ->{ c: false, ...o } : { c: false; ...{ a: number; b: string; } } +>{ c: false, ...o } : { a: number; b: string; c: false; } >c : boolean >false : false >o : any @@ -55,7 +55,7 @@ let ignore: { a: number, b: string } = >b : string { b: 'ignored', ...o } ->{ b: 'ignored', ...o } : { b: string; ...{ a: number; b: string; } } +>{ b: 'ignored', ...o } : { a: number; b: string; } >b : string >'ignored' : "ignored" >o : any @@ -66,7 +66,7 @@ let override: { a: number, b: string } = >b : string { ...o, b: 'override' } ->{ ...o, b: 'override' } : { ...{ a: number; b: string; }; b: string; } +>{ ...o, b: 'override' } : { b: string; a: number; } >o : any >b : string >'override' : "override" @@ -78,8 +78,8 @@ let nested: { a: number, b: boolean, c: string } = >c : string { ...{ a: 3, ...{ b: false, c: 'overriden' } }, c: 'whatever' } ->{ ...{ a: 3, ...{ b: false, c: 'overriden' } }, c: 'whatever' } : { ...{ a: number; ...{ b: boolean; c: string; } }; c: string; } ->{ a: 3, ...{ b: false, c: 'overriden' } } : { a: number; ...{ b: boolean; c: string; } } +>{ ...{ a: 3, ...{ b: false, c: 'overriden' } }, c: 'whatever' } : { c: string; b: boolean; a: number; } +>{ a: 3, ...{ b: false, c: 'overriden' } } : { b: boolean; c: string; a: number; } >a : number >3 : 3 >{ b: false, c: 'overriden' } : { b: boolean; c: string; } @@ -97,7 +97,7 @@ let combined: { a: number, b: string, c: boolean } = >c : boolean { ...o, ...o2 } ->{ ...o, ...o2 } : { ...{ a: number; b: string; }; ...{ b: string; c: boolean; } } +>{ ...o, ...o2 } : { b: string; c: boolean; a: number; } >o : any >o2 : any @@ -108,7 +108,7 @@ let combinedBefore: { a: number, b: string, c: boolean } = >c : boolean { b: 'ok', ...o, ...o2 } ->{ b: 'ok', ...o, ...o2 } : { b: string; ...{ a: number; b: string; }; ...{ b: string; c: boolean; } } +>{ b: 'ok', ...o, ...o2 } : { b: string; c: boolean; a: number; } >b : string >'ok' : "ok" >o : any @@ -121,7 +121,7 @@ let combinedMid: { a: number, b: string, c: boolean } = >c : boolean { ...o, b: 'ok', ...o2 } ->{ ...o, b: 'ok', ...o2 } : { ...{ a: number; b: string; }; b: string; ...{ b: string; c: boolean; } } +>{ ...o, b: 'ok', ...o2 } : { b: string; c: boolean; a: number; } >o : any >b : string >'ok' : "ok" @@ -134,7 +134,7 @@ let combinedAfter: { a: number, b: string, c: boolean } = >c : boolean { ...o, ...o2, b: 'ok' } ->{ ...o, ...o2, b: 'ok' } : { ...{ a: number; b: string; }; ...{ b: string; c: boolean; }; b: string; } +>{ ...o, ...o2, b: 'ok' } : { b: string; c: boolean; a: number; } >o : any >o2 : any >b : string @@ -148,8 +148,8 @@ let combinedNested: { a: number, b: boolean, c: string, d: string } = >d : string { ...{ a: 4, ...{ b: false, c: 'overriden' } }, d: 'actually new', ...{ a: 5, d: 'maybe new' } } ->{ ...{ a: 4, ...{ b: false, c: 'overriden' } }, d: 'actually new', ...{ a: 5, d: 'maybe new' } } : { ...{ a: number; ...{ b: boolean; c: string; } }; d: string; ...{ a: number; d: string; } } ->{ a: 4, ...{ b: false, c: 'overriden' } } : { a: number; ...{ b: boolean; c: string; } } +>{ ...{ a: 4, ...{ b: false, c: 'overriden' } }, d: 'actually new', ...{ a: 5, d: 'maybe new' } } : { a: number; d: string; b: boolean; c: string; } +>{ a: 4, ...{ b: false, c: 'overriden' } } : { b: boolean; c: string; a: number; } >a : number >4 : 4 >{ b: false, c: 'overriden' } : { b: boolean; c: string; } @@ -172,8 +172,8 @@ let combinedNestedChangeType: { a: number, b: boolean, c: number } = >c : number { ...{ a: 1, ...{ b: false, c: 'overriden' } }, c: -1 } ->{ ...{ a: 1, ...{ b: false, c: 'overriden' } }, c: -1 } : { ...{ a: number; ...{ b: boolean; c: string; } }; c: number; } ->{ a: 1, ...{ b: false, c: 'overriden' } } : { a: number; ...{ b: boolean; c: string; } } +>{ ...{ a: 1, ...{ b: false, c: 'overriden' } }, c: -1 } : { c: number; b: boolean; a: number; } +>{ a: 1, ...{ b: false, c: 'overriden' } } : { b: boolean; c: string; a: number; } >a : number >1 : 1 >{ b: false, c: 'overriden' } : { b: boolean; c: string; } @@ -192,9 +192,9 @@ let propertyNested: { a: { a: number, b: string } } = >b : string { a: { ... o } } ->{ a: { ... o } } : { a: { ...{ a: number; b: string; } }; } ->a : { ...{ a: number; b: string; } } ->{ ... o } : { ...{ a: number; b: string; } } +>{ a: { ... o } } : { a: { a: number; b: string; }; } +>a : { a: number; b: string; } +>{ ... o } : { a: number; b: string; } >o : any // accessors don't copy the descriptor @@ -211,7 +211,7 @@ let getter: { a: number, c: number } = >c : number { ...op, c: 7 } ->{ ...op, c: 7 } : { ...{ readonly a: number; }; c: number; } +>{ ...op, c: 7 } : { c: number; readonly a: number; } >op : any >c : number >7 : 7 @@ -260,7 +260,7 @@ let c: C = new C() let spreadC: { p: number } = { ...c } >spreadC : { p: number; } >p : number ->{ ...c } : { ...C } +>{ ...c } : { p: number; } >c : any // own methods are enumerable @@ -268,7 +268,7 @@ let cplus: { p: number, plus(): void } = { ...c, plus() { return this.p + 1; } } >cplus : { p: number; plus(): void; } >p : number >plus : () => void ->{ ...c, plus() { return this.p + 1; } } : { ...C; plus(): any; } +>{ ...c, plus() { return this.p + 1; } } : { plus(): any; p: number; } >c : any >plus : () => any >this.p + 1 : any @@ -290,7 +290,7 @@ let changeTypeAfter: { a: string, b: string } = >b : string { ...o, a: 'wrong type?' } ->{ ...o, a: 'wrong type?' } : { ...{ a: number; b: string; }; a: string; } +>{ ...o, a: 'wrong type?' } : { a: string; b: string; } >o : any >a : string >'wrong type?' : "wrong type?" @@ -301,7 +301,7 @@ let changeTypeBefore: { a: number, b: string } = >b : string { a: 'wrong type?', ...o }; ->{ a: 'wrong type?', ...o } : { a: string; ...{ a: number; b: string; } } +>{ a: 'wrong type?', ...o } : { a: number; b: string; } >a : string >'wrong type?' : "wrong type?" >o : any @@ -312,7 +312,7 @@ let changeTypeBoth: { a: string, b: number } = >b : number { ...o, ...swap }; ->{ ...o, ...swap } : { ...{ a: number; b: string; }; ...{ a: string; b: number; } } +>{ ...o, ...swap } : { a: string; b: number; } >o : any >swap : any @@ -336,7 +336,7 @@ let optionalNumber: { sn?: number }; let optionalUnionStops: { sn: string | number | boolean } = { ...definiteBoolean, ...definiteString, ...optionalNumber }; >optionalUnionStops : { sn: string | number | boolean; } >sn : string | number | boolean ->{ ...definiteBoolean, ...definiteString, ...optionalNumber } : { ...{ sn: boolean; }; ...{ sn: string; }; ...{ sn?: number; } } +>{ ...definiteBoolean, ...definiteString, ...optionalNumber } : { sn: string | number; } >definiteBoolean : any >definiteString : any >optionalNumber : any @@ -344,7 +344,7 @@ let optionalUnionStops: { sn: string | number | boolean } = { ...definiteBoolean let optionalUnionDuplicates: { sn: string | number } = { ...definiteBoolean, ...definiteString, ...optionalString, ...optionalNumber }; >optionalUnionDuplicates : { sn: string | number; } >sn : string | number ->{ ...definiteBoolean, ...definiteString, ...optionalString, ...optionalNumber } : { ...{ sn: boolean; }; ...{ sn: string; }; ...{ sn?: string; }; ...{ sn?: number; } } +>{ ...definiteBoolean, ...definiteString, ...optionalString, ...optionalNumber } : { sn: string | number; } >definiteBoolean : any >definiteString : any >optionalString : any @@ -353,7 +353,7 @@ let optionalUnionDuplicates: { sn: string | number } = { ...definiteBoolean, ... let allOptional: { sn?: string | number } = { ...optionalString, ...optionalNumber }; >allOptional : { sn?: string | number; } >sn : string | number ->{ ...optionalString, ...optionalNumber } : { ...{ sn?: string; }; ...{ sn?: number; } } +>{ ...optionalString, ...optionalNumber } : { sn?: string | number; } >optionalString : any >optionalNumber : any @@ -364,7 +364,7 @@ let computedFirst: { a: number, b: string, "before everything": number } = >b : string { ['before everything']: 12, ...o, b: 'yes' } ->{ ['before everything']: 12, ...o, b: 'yes' } : { ['before everything']: number; ...{ a: number; b: string; }; b: string; } +>{ ['before everything']: 12, ...o, b: 'yes' } : { b: string; a: number; ['before everything']: number; } >'before everything' : "before everything" >12 : 12 >o : any @@ -378,7 +378,7 @@ let computedMiddle: { a: number, b: string, c: boolean, "in the middle": number >c : boolean { ...o, ['in the middle']: 13, b: 'maybe?', ...o2 } ->{ ...o, ['in the middle']: 13, b: 'maybe?', ...o2 } : { ...{ a: number; b: string; }; ['in the middle']: number; b: string; ...{ b: string; c: boolean; } } +>{ ...o, ['in the middle']: 13, b: 'maybe?', ...o2 } : { b: string; c: boolean; ['in the middle']: number; a: number; } >o : any >'in the middle' : "in the middle" >13 : 13 @@ -392,7 +392,7 @@ let computedAfter: { a: number, b: string, "at the end": number } = >b : string { ...o, b: 'yeah', ['at the end']: 14 } ->{ ...o, b: 'yeah', ['at the end']: 14 } : { ...{ a: number; b: string; }; b: string; ['at the end']: number; } +>{ ...o, b: 'yeah', ['at the end']: 14 } : { b: string; ['at the end']: number; a: number; } >o : any >b : string >'yeah' : "yeah" @@ -408,7 +408,7 @@ let shortCutted: { a: number, b: string } = { ...o, a } >shortCutted : { a: number; b: string; } >a : number >b : string ->{ ...o, a } : { ...{ a: number; b: string; }; a: number; } +>{ ...o, a } : { a: number; b: string; } >o : any >a : number @@ -441,7 +441,7 @@ let exclusive: { id: string, a: number, b: string, c: string, d: boolean } = >d : boolean f({ a: 1, b: 'yes' }, { c: 'no', d: false }) ->f({ a: 1, b: 'yes' }, { c: 'no', d: false }) : { id: string; ...{ a: number; b: string; }; ...{ c: string; d: boolean; } } +>f({ a: 1, b: 'yes' }, { c: 'no', d: false }) : { c: string; d: boolean; a: number; b: string; id: string; } >f : (t: T, u: U) => { id: string; ...T; ...U } >{ a: 1, b: 'yes' } : { a: number; b: string; } >a : number @@ -461,7 +461,7 @@ let overlap: { id: string, a: number, b: string } = >b : string f({ a: 1 }, { a: 2, b: 'extra' }) ->f({ a: 1 }, { a: 2, b: 'extra' }) : { id: string; ...{ a: number; }; ...{ a: number; b: string; } } +>f({ a: 1 }, { a: 2, b: 'extra' }) : { a: number; b: string; id: string; } >f : (t: T, u: U) => { id: string; ...T; ...U } >{ a: 1 } : { a: number; } >a : number @@ -478,7 +478,7 @@ let overlapConflict: { id:string, a: string } = >a : string f({ a: 1 }, { a: 'mismatch' }) ->f({ a: 1 }, { a: 'mismatch' }) : { id: string; ...{ a: number; }; ...{ a: string; } } +>f({ a: 1 }, { a: 'mismatch' }) : { a: string; id: string; } >f : (t: T, u: U) => { id: string; ...T; ...U } >{ a: 1 } : { a: number; } >a : number @@ -495,7 +495,7 @@ let overwriteId: { id: boolean, a: number, c: number, d: string } = >d : string f({ a: 1, id: true }, { c: 1, d: 'no' }) ->f({ a: 1, id: true }, { c: 1, d: 'no' }) : { id: string; ...{ a: number; id: boolean; }; ...{ c: number; d: string; } } +>f({ a: 1, id: true }, { c: 1, d: 'no' }) : { c: number; d: string; a: number; id: boolean; } >f : (t: T, u: U) => { id: string; ...T; ...U } >{ a: 1, id: true } : { a: number; id: true; } >a : number @@ -515,13 +515,13 @@ class D { m() { }; q = 2; } >2 : 2 let classesAreWrong: { id: string, ...C, ...D } = ->classesAreWrong : { id: string; ...C; ...D } +>classesAreWrong : { q: number; p: number; id: string; } >id : string >C : C >D : D f(new C(), new D()) ->f(new C(), new D()) : { id: string; ...C; ...D } +>f(new C(), new D()) : { q: number; p: number; id: string; } >f : (t: T, u: U) => { id: string; ...T; ...U } >new C() : C >C : typeof C diff --git a/tests/baselines/reference/objectSpreadGeneric.errors.txt b/tests/baselines/reference/objectSpreadGeneric.errors.txt index 16dfc835d26..6e55040f223 100644 --- a/tests/baselines/reference/objectSpreadGeneric.errors.txt +++ b/tests/baselines/reference/objectSpreadGeneric.errors.txt @@ -1,22 +1,31 @@ -tests/cases/conformance/types/spread/objectSpreadGeneric.ts(4,11): error TS2322: Type '{ ...T; ...U; ...V }' is not assignable to type '{ ...V; ...U; ...T }'. -tests/cases/conformance/types/spread/objectSpreadGeneric.ts(5,11): error TS2322: Type '{ ...T; ...U; ...V }' is not assignable to type '{ ...U; ...T; ...V }'. -tests/cases/conformance/types/spread/objectSpreadGeneric.ts(6,11): error TS2322: Type '{ ...T; ...U; ...V }' is not assignable to type '{ ...U; ...V }'. -tests/cases/conformance/types/spread/objectSpreadGeneric.ts(7,11): error TS2322: Type '{ ...T; ...U; ...V }' is not assignable to type '{ ...T; ...V }'. -tests/cases/conformance/types/spread/objectSpreadGeneric.ts(8,11): error TS2322: Type '{ ...T; ...U; ...V }' is not assignable to type '{ ...T; ...U }'. -tests/cases/conformance/types/spread/objectSpreadGeneric.ts(13,11): error TS2322: Type '{}' is not assignable to type '{ ...T; ...U }'. -tests/cases/conformance/types/spread/objectSpreadGeneric.ts(26,11): error TS2322: Type '{ first: string; ...T; second: string; ...U; third: string; }' is not assignable to type '{ first: string; second: string; ...T; third: string; }'. -tests/cases/conformance/types/spread/objectSpreadGeneric.ts(34,11): error TS2322: Type '{ firrrrrrst: string; ...T; second: string; ...U; third: string; }' is not assignable to type '{ first: string; ...T; second: string; ...U; third: string; }'. - Property 'first' is missing in type '{ firrrrrrst: string; ...T; second: string; ...U; third: string; }'. -tests/cases/conformance/types/spread/objectSpreadGeneric.ts(36,11): error TS2322: Type '{ first: string; ...T; ssssssssecond: string; ...U; third: string; }' is not assignable to type '{ first: string; ...T; second: string; ...U; third: string; }'. - Property 'second' is missing in type '{ first: string; ...T; ssssssssecond: string; ...U; third: string; }'. -tests/cases/conformance/types/spread/objectSpreadGeneric.ts(38,11): error TS2322: Type '{ first: string; ...T; second: string; ...U; thirrrrrrrd: string; }' is not assignable to type '{ first: string; ...T; second: string; ...U; third: string; }'. - Property 'third' is missing in type '{ first: string; ...T; second: string; ...U; thirrrrrrrd: string; }'. +tests/cases/conformance/types/spread/objectSpreadGeneric.ts(9,5): error TS2322: Type '{ ...U }' is not assignable to type 'U'. +tests/cases/conformance/types/spread/objectSpreadGeneric.ts(10,11): error TS2322: Type '{ ...T; ...U; ...V }' is not assignable to type '{ ...V; ...U; ...T }'. +tests/cases/conformance/types/spread/objectSpreadGeneric.ts(11,11): error TS2322: Type '{ ...T; ...U; ...V }' is not assignable to type '{ ...U; ...T; ...V }'. +tests/cases/conformance/types/spread/objectSpreadGeneric.ts(12,11): error TS2322: Type '{ ...T; ...U; ...V }' is not assignable to type '{ ...U; ...V }'. +tests/cases/conformance/types/spread/objectSpreadGeneric.ts(13,11): error TS2322: Type '{ ...T; ...U; ...V }' is not assignable to type '{ ...T; ...V }'. +tests/cases/conformance/types/spread/objectSpreadGeneric.ts(14,11): error TS2322: Type '{ ...T; ...U; ...V }' is not assignable to type '{ ...T; ...U }'. +tests/cases/conformance/types/spread/objectSpreadGeneric.ts(19,11): error TS2322: Type '{}' is not assignable to type '{ ...T; ...U }'. +tests/cases/conformance/types/spread/objectSpreadGeneric.ts(32,11): error TS2322: Type '{ first: string; ...T; second: string; ...U; third: string; }' is not assignable to type '{ first: string; second: string; ...T; third: string; }'. +tests/cases/conformance/types/spread/objectSpreadGeneric.ts(40,11): error TS2322: Type '{ firrrrrrst: string; ...T; second: string; ...U; third: string; }' is not assignable to type '{ first: string; ...T; second: string; ...U; third: string; }'. + Property 'first' is missing in type '{ third: string; second: string; firrrrrrst: string; }'. +tests/cases/conformance/types/spread/objectSpreadGeneric.ts(42,11): error TS2322: Type '{ first: string; ...T; ssssssssecond: string; ...U; third: string; }' is not assignable to type '{ first: string; ...T; second: string; ...U; third: string; }'. + Property 'second' is missing in type '{ third: string; ssssssssecond: string; first: string; }'. +tests/cases/conformance/types/spread/objectSpreadGeneric.ts(44,11): error TS2322: Type '{ first: string; ...T; second: string; ...U; thirrrrrrrd: string; }' is not assignable to type '{ first: string; ...T; second: string; ...U; third: string; }'. + Property 'third' is missing in type '{ thirrrrrrrd: string; second: string; first: string; }'. -==== tests/cases/conformance/types/spread/objectSpreadGeneric.ts (10 errors) ==== +==== tests/cases/conformance/types/spread/objectSpreadGeneric.ts (11 errors) ==== function f(t: T, u: U, v: V): void { let o: { ...T, ...U, ...V }; + 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 + ~ +!!! error TS2322: Type '{ ...U }' is not assignable to type 'U'. const reversed: { ...V, ...U, ...T } = o; // error, reversed ~~~~~~~~ !!! error TS2322: Type '{ ...T; ...U; ...V }' is not assignable to type '{ ...V; ...U; ...T }'. @@ -64,17 +73,17 @@ tests/cases/conformance/types/spread/objectSpreadGeneric.ts(38,11): error TS2322 const mismatchFirst: { first: string, ...T, second: string, ...U, third: string } = ~~~~~~~~~~~~~ !!! error TS2322: Type '{ firrrrrrst: string; ...T; second: string; ...U; third: string; }' is not assignable to type '{ first: string; ...T; second: string; ...U; third: string; }'. -!!! error TS2322: Property 'first' is missing in type '{ firrrrrrst: string; ...T; second: string; ...U; third: string; }'. +!!! error TS2322: Property 'first' is missing in type '{ third: string; second: string; firrrrrrst: string; }'. { firrrrrrst: '1', ...t, second: '2', ...u, third: '3' }; // error, 'first' not found const mismatchSecond: { first: string, ...T, second: string, ...U, third: string } = ~~~~~~~~~~~~~~ !!! error TS2322: Type '{ first: string; ...T; ssssssssecond: string; ...U; third: string; }' is not assignable to type '{ first: string; ...T; second: string; ...U; third: string; }'. -!!! error TS2322: Property 'second' is missing in type '{ first: string; ...T; ssssssssecond: string; ...U; third: string; }'. +!!! error TS2322: Property 'second' is missing in type '{ third: string; ssssssssecond: string; first: string; }'. { first: '1', ...t, ssssssssecond: '2', ...u, third: '3' }; // error, 'second' not found const mismatchLast: { first: string, ...T, second: string, ...U, third: string } = ~~~~~~~~~~~~ !!! error TS2322: Type '{ first: string; ...T; second: string; ...U; thirrrrrrrd: string; }' is not assignable to type '{ first: string; ...T; second: string; ...U; third: string; }'. -!!! error TS2322: Property 'third' is missing in type '{ first: string; ...T; second: string; ...U; thirrrrrrrd: string; }'. +!!! error TS2322: Property 'third' is missing in type '{ thirrrrrrrd: string; second: string; first: string; }'. { first: '1', ...t, second: '2', ...u, thirrrrrrrd: '3' }; // error, 'third' not found } \ No newline at end of file diff --git a/tests/baselines/reference/objectSpreadGeneric.js b/tests/baselines/reference/objectSpreadGeneric.js index 593ab73f98f..9414b9ef76e 100644 --- a/tests/baselines/reference/objectSpreadGeneric.js +++ b/tests/baselines/reference/objectSpreadGeneric.js @@ -1,7 +1,13 @@ //// [objectSpreadGeneric.ts] function f(t: T, u: U, v: V): void { let o: { ...T, ...U, ...V }; + 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 @@ -52,7 +58,13 @@ var __assign = (this && this.__assign) || Object.assign || function(t) { }; function f(t, u, v) { var o; + var uus; + var us; var same = 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 var reversed = o; // error, reversed var reversed2 = o; // error, U and T are still reversed var missingT = o; // error, missing T diff --git a/tests/baselines/reference/objectSpreadIndexSignature.types b/tests/baselines/reference/objectSpreadIndexSignature.types index 9a31b0c4451..6e9ba881db1 100644 --- a/tests/baselines/reference/objectSpreadIndexSignature.types +++ b/tests/baselines/reference/objectSpreadIndexSignature.types @@ -9,7 +9,7 @@ class C { >c : boolean } let c: { ...C, b: string, c?: string, [n: number]: string }; ->c : { ...C; b: string; c?: string; [n: number]: string; } +>c : { [n: number]: string; b: string; c: string | boolean; a: number; } >C : C >b : string >c : string @@ -18,13 +18,13 @@ let c: { ...C, b: string, c?: string, [n: number]: string }; let n: number = c.a; >n : number >c.a : number ->c : { ...C; b: string; c?: string; [n: number]: string; } +>c : { [n: number]: string; b: string; c: string | boolean; a: number; } >a : number let s: string = c[12]; >s : string >c[12] : string ->c : { ...C; b: string; c?: string; [n: number]: string; } +>c : { [n: number]: string; b: string; c: string | boolean; a: number; } >12 : 12 interface Indexed { @@ -37,7 +37,7 @@ interface Indexed { >a : number } let i: { ...Indexed, b: number }; ->i : { ...Indexed; b: number; [n: string]: number; } +>i : { [n: string]: number; b: number; a: number; } >Indexed : Indexed >b : number @@ -45,14 +45,14 @@ n = i[101]; >n = i[101] : number >n : number >i[101] : number ->i : { ...Indexed; b: number; [n: string]: number; } +>i : { [n: string]: number; b: number; a: number; } >101 : 101 n = i.b; >n = i.b : number >n : number >i.b : number ->i : { ...Indexed; b: number; [n: string]: number; } +>i : { [n: string]: number; b: number; a: number; } >b : number interface Indexed2 { @@ -65,7 +65,7 @@ interface Indexed2 { >c : boolean } let ii: { ...Indexed, ...Indexed2, b: boolean, d: number }; ->ii : { ...Indexed; ...Indexed2; b: boolean; d: number; [x: string]: number | boolean; } +>ii : { [x: string]: number | boolean; b: boolean; d: number; c: boolean; a: number; } >Indexed : Indexed >Indexed2 : Indexed2 >b : boolean @@ -74,6 +74,6 @@ let ii: { ...Indexed, ...Indexed2, b: boolean, d: number }; let nb: number | boolean = ii[1001]; >nb : number | boolean >ii[1001] : number | boolean ->ii : { ...Indexed; ...Indexed2; b: boolean; d: number; [x: string]: number | boolean; } +>ii : { [x: string]: number | boolean; b: boolean; d: number; c: boolean; a: number; } >1001 : 1001 diff --git a/tests/baselines/reference/objectSpreadNegative.errors.txt b/tests/baselines/reference/objectSpreadNegative.errors.txt index 1ee3acb823c..38e564c3b5d 100644 --- a/tests/baselines/reference/objectSpreadNegative.errors.txt +++ b/tests/baselines/reference/objectSpreadNegative.errors.txt @@ -1,20 +1,23 @@ -tests/cases/conformance/types/spread/objectSpreadNegative.ts(13,30): error TS2339: Property 'x' does not exist on type '{ ...PublicX; ...PrivateOptionalX }'. -tests/cases/conformance/types/spread/objectSpreadNegative.ts(16,5): error TS2322: Type '{ ...{ sn?: string; }; ...{ sn?: number; } }' is not assignable to type '{ sn: string | number; }'. - Property 'sn' is optional in type '{ ...{ sn?: string; }; ...{ sn?: number; } }' but required in type '{ sn: string | number; }'. -tests/cases/conformance/types/spread/objectSpreadNegative.ts(22,5): error TS2322: Type '{ s: string; }' is not assignable to type '{ ...Bool; ...Str }'. -tests/cases/conformance/types/spread/objectSpreadNegative.ts(24,1): error TS2322: Type 'Bool' is not assignable to type '{ ...Bool; ...Str }'. -tests/cases/conformance/types/spread/objectSpreadNegative.ts(27,15): error TS2697: Spread properties must be identifiers, property accesses, or object literals. -tests/cases/conformance/types/spread/objectSpreadNegative.ts(28,15): error TS2697: Spread properties must be identifiers, property accesses, or object literals. -tests/cases/conformance/types/spread/objectSpreadNegative.ts(31,36): error TS2300: Duplicate identifier 'b'. -tests/cases/conformance/types/spread/objectSpreadNegative.ts(31,53): error TS2300: Duplicate identifier 'b'. -tests/cases/conformance/types/spread/objectSpreadNegative.ts(36,12): error TS2339: Property 'b' does not exist on type '{ ...{ b: number; } }'. -tests/cases/conformance/types/spread/objectSpreadNegative.ts(42,9): error TS2339: Property 'm' does not exist on type '{ ...C }'. -tests/cases/conformance/types/spread/objectSpreadNegative.ts(45,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '{ ...PublicX }' has no compatible call signatures. -tests/cases/conformance/types/spread/objectSpreadNegative.ts(46,1): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. -tests/cases/conformance/types/spread/objectSpreadNegative.ts(48,39): error TS2697: Spread properties must be identifiers, property accesses, or object literals. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(11,21): error TS2339: Property 'x' does not exist on type '{}'. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(14,5): error TS2322: Type '{ sn?: string | number; }' is not assignable to type '{ sn: string | number; }'. + Property 'sn' is optional in type '{ sn?: string | number; }' but required in type '{ sn: string | number; }'. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(20,5): error TS2322: Type '{ s: string; }' is not assignable to type '{ s: string; b: boolean; }'. + Property 'b' is missing in type '{ s: string; }'. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(22,1): error TS2322: Type 'Bool' is not assignable to type '{ s: string; b: boolean; }'. + Property 's' is missing in type 'Bool'. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(25,15): error TS2697: Spread properties must be identifiers, property accesses, or object literals. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(26,15): error TS2697: Spread properties must be identifiers, property accesses, or object literals. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(29,36): error TS2300: Duplicate identifier 'b'. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(29,53): error TS2300: Duplicate identifier 'b'. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(34,12): error TS2339: Property 'b' does not exist on type '{}'. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(40,9): error TS2339: Property 'm' does not exist on type '{ p: number; }'. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(43,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '{ x: number; }' has no compatible call signatures. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(44,1): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(47,39): error TS2697: Spread properties must be identifiers, property accesses, or object literals. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(51,12): error TS2322: Type '{ ...U }' is not assignable to type 'U'. -==== tests/cases/conformance/types/spread/objectSpreadNegative.ts (13 errors) ==== +==== tests/cases/conformance/types/spread/objectSpreadNegative.ts (14 errors) ==== let o = { a: 1, b: 'no' } /// private propagates @@ -24,18 +27,16 @@ tests/cases/conformance/types/spread/objectSpreadNegative.ts(48,39): error TS269 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 - ~ -!!! error TS2339: Property 'x' does not exist on type '{ ...PublicX; ...PrivateOptionalX }'. + let o3: { ...PublicX, ...PrivateOptionalX }; + let sn: number = o3.x; // error, x is private + ~ +!!! error TS2339: Property 'x' does not exist on type '{}'. let optionalString: { sn?: string }; let optionalNumber: { sn?: number }; let allOptional: { sn: string | number } = { ...optionalString, ...optionalNumber }; ~~~~~~~~~~~ -!!! error TS2322: Type '{ ...{ sn?: string; }; ...{ sn?: number; } }' is not assignable to type '{ sn: string | number; }'. -!!! error TS2322: Property 'sn' is optional in type '{ ...{ sn?: string; }; ...{ sn?: number; } }' but required in type '{ sn: string | number; }'. +!!! error TS2322: Type '{ sn?: string | number; }' is not assignable to type '{ sn: string | number; }'. +!!! error TS2322: Property 'sn' is optional in type '{ sn?: string | number; }' but required in type '{ sn: string | number; }'. // error, 'sn' is optional in source, required in target // assignability as target @@ -43,11 +44,13 @@ tests/cases/conformance/types/spread/objectSpreadNegative.ts(48,39): error TS269 interface Str { s: string }; let spread: { ...Bool, ...Str } = { s: 'foo' }; // error, missing 'b' ~~~~~~ -!!! error TS2322: Type '{ s: string; }' is not assignable to type '{ ...Bool; ...Str }'. +!!! error TS2322: Type '{ s: string; }' is not assignable to type '{ s: string; b: boolean; }'. +!!! error TS2322: Property 'b' is missing in type '{ s: string; }'. let b: Bool; spread = b; // error, missing 's' ~~~~~~ -!!! error TS2322: Type 'Bool' is not assignable to type '{ ...Bool; ...Str }'. +!!! error TS2322: Type 'Bool' is not assignable to type '{ s: string; b: boolean; }'. +!!! error TS2322: Property 's' is missing in type 'Bool'. // expressions are not allowed let o1 = { ...1 + 1 }; @@ -69,7 +72,7 @@ tests/cases/conformance/types/spread/objectSpreadNegative.ts(48,39): error TS269 let setterOnly = { ...{ set b (bad: number) { } } }; setterOnly.b = 12; // error, 'b' does not exist ~ -!!! error TS2339: Property 'b' does not exist on type '{ ...{ b: number; } }'. +!!! error TS2339: Property 'b' does not exist on type '{}'. // methods are skipped because they aren't enumerable class C { p = 1; m() { } } @@ -77,17 +80,25 @@ tests/cases/conformance/types/spread/objectSpreadNegative.ts(48,39): error TS269 let spreadC = { ...c } spreadC.m(); // error 'm' is not in '{ ... c }' ~ -!!! error TS2339: Property 'm' does not exist on type '{ ...C }'. +!!! error TS2339: Property 'm' does not exist on type '{ p: number; }'. let callableConstructableSpread: { ...PublicX, (n: number): number, new (p: number) }; callableConstructableSpread(12); // error, no call signature ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '{ ...PublicX }' has no compatible call signatures. +!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '{ x: number; }' has no compatible call signatures. new callableConstructableSpread(12); // error, no construct signature ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. + let publicx: PublicX; let callableSpread = { ...publicx, ...(n => n + 1) }; // error, can't spread functions ~~~~~~~~~~~~ !!! error TS2697: Spread properties must be identifiers, property accesses, or object literals. + + // { ...U } is not assignable to U + function override(initial: U, override: U): U { + return { ...initial, ...override }; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '{ ...U }' is not assignable to type 'U'. + } \ No newline at end of file diff --git a/tests/baselines/reference/objectSpreadNegative.js b/tests/baselines/reference/objectSpreadNegative.js index 685760f9444..6874380599b 100644 --- a/tests/baselines/reference/objectSpreadNegative.js +++ b/tests/baselines/reference/objectSpreadNegative.js @@ -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,7 +44,13 @@ 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 +function override(initial: U, override: U): U { + return { ...initial, ...override }; +} //// [objectSpreadNegative.js] @@ -70,9 +74,7 @@ var PublicX = (function () { } return PublicX; }()); -var privateOptionalx; -var publicx; -var o3 = __assign({}, publicx, privateOptionalx); +var o3; var sn = o3.x; // error, x is private var optionalString; var optionalNumber; @@ -105,4 +107,9 @@ spreadC.m(); // error 'm' is not in '{ ... c }' var callableConstructableSpread; callableConstructableSpread(12); // error, no call signature new callableConstructableSpread(12); // error, no construct signature +var publicx; var callableSpread = __assign({}, publicx, (function (n) { return n + 1; })); // error, can't spread functions +// { ...U } is not assignable to U +function override(initial, override) { + return __assign({}, initial, override); +} diff --git a/tests/baselines/reference/objectSpreadScenarios.js b/tests/baselines/reference/objectSpreadScenarios.js index 64739a2b298..96ac98d2d35 100644 --- a/tests/baselines/reference/objectSpreadScenarios.js +++ b/tests/baselines/reference/objectSpreadScenarios.js @@ -4,7 +4,7 @@ interface B1 { b: number }; function override(initial: U, override: U): { ...U, ...U } { return { ...initial, ...override }; } -function update(this: { u: U }, override: U): void { +function update(this: { u: { ...U } }, override: U): void { this.u = { ...this.u, ...override }; } function mixin(one: T, two: U): { ...T, ...U } { diff --git a/tests/baselines/reference/objectSpreadScenarios.symbols b/tests/baselines/reference/objectSpreadScenarios.symbols index 784e340a10c..cf1e1833ac9 100644 --- a/tests/baselines/reference/objectSpreadScenarios.symbols +++ b/tests/baselines/reference/objectSpreadScenarios.symbols @@ -19,13 +19,13 @@ function override(initial: U, override: U): { ...U, ...U } { return { ...initial, ...override }; } -function update(this: { u: U }, override: U): void { +function update(this: { u: { ...U } }, override: U): void { >update : Symbol(update, Decl(objectSpreadScenarios.ts, 4, 1)) >U : Symbol(U, Decl(objectSpreadScenarios.ts, 5, 16)) >this : Symbol(this, Decl(objectSpreadScenarios.ts, 5, 19)) >u : Symbol(u, Decl(objectSpreadScenarios.ts, 5, 26)) >U : Symbol(U, Decl(objectSpreadScenarios.ts, 5, 16)) ->override : Symbol(override, Decl(objectSpreadScenarios.ts, 5, 34)) +>override : Symbol(override, Decl(objectSpreadScenarios.ts, 5, 41)) >U : Symbol(U, Decl(objectSpreadScenarios.ts, 5, 16)) this.u = { ...this.u, ...override }; diff --git a/tests/baselines/reference/objectSpreadScenarios.types b/tests/baselines/reference/objectSpreadScenarios.types index 5330029afe1..2d1aa47bd50 100644 --- a/tests/baselines/reference/objectSpreadScenarios.types +++ b/tests/baselines/reference/objectSpreadScenarios.types @@ -8,7 +8,7 @@ interface B1 { b: number }; >b : number function override(initial: U, override: U): { ...U, ...U } { ->override : (initial: U, override: U) => { ...U; ...U } +>override : (initial: U, override: U) => { ...U } >U : U >initial : U >U : U @@ -18,28 +18,28 @@ function override(initial: U, override: U): { ...U, ...U } { >U : U return { ...initial, ...override }; ->{ ...initial, ...override } : { ...U; ...U } +>{ ...initial, ...override } : { ...U } >initial : any >override : any } -function update(this: { u: U }, override: U): void { ->update : (this: { u: U; }, override: U) => void +function update(this: { u: { ...U } }, override: U): void { +>update : (this: { u: { ...U }; }, override: U) => void >U : U ->this : { u: U; } ->u : U +>this : { u: { ...U }; } +>u : { ...U } >U : U >override : U >U : U this.u = { ...this.u, ...override }; ->this.u = { ...this.u, ...override } : { ...U; ...U } ->this.u : U ->this : { u: U; } ->u : U ->{ ...this.u, ...override } : { ...U; ...U } ->this.u : U ->this : { u: U; } ->u : U +>this.u = { ...this.u, ...override } : { ...U } +>this.u : { ...U } +>this : { u: { ...U }; } +>u : { ...U } +>{ ...this.u, ...override } : { ...U } +>this.u : { ...U } +>this : { u: { ...U }; } +>u : { ...U } >override : any } function mixin(one: T, two: U): { ...T, ...U } { @@ -73,34 +73,34 @@ let b1: B1 = { b: 101 }; >101 : 101 a1 = override(a1, { a: false }); ->a1 = override(a1, { a: false }) : { ...A1; ...A1 } +>a1 = override(a1, { a: false }) : { a: boolean; } >a1 : A1 ->override(a1, { a: false }) : { ...A1; ...A1 } ->override : (initial: U, override: U) => { ...U; ...U } +>override(a1, { a: false }) : { a: boolean; } +>override : (initial: U, override: U) => { ...U } >a1 : A1 >{ a: false } : { a: false; } >a : boolean >false : false let host = { u: a1, update }; ->host : { u: A1; update: (this: { u: U; }, override: U) => void; } ->{ u: a1, update } : { u: A1; update: (this: { u: U; }, override: U) => void; } +>host : { u: A1; update: (this: { u: { ...U }; }, override: U) => void; } +>{ u: a1, update } : { u: A1; update: (this: { u: { ...U }; }, override: U) => void; } >u : A1 >a1 : A1 ->update : (this: { u: U; }, override: U) => void +>update : (this: { u: { ...U }; }, override: U) => void host.update({ a: false }); >host.update({ a: false }) : void ->host.update : (this: { u: U; }, override: U) => void ->host : { u: A1; update: (this: { u: U; }, override: U) => void; } ->update : (this: { u: U; }, override: U) => void +>host.update : (this: { u: { ...U }; }, override: U) => void +>host : { u: A1; update: (this: { u: { ...U }; }, override: U) => void; } +>update : (this: { u: { ...U }; }, override: U) => void >{ a: false } : { a: false; } >a : boolean >false : false let mixed = mixin(a1, b1); ->mixed : { ...A1; ...B1 } ->mixin(a1, b1) : { ...A1; ...B1 } +>mixed : { b: number; a: boolean; } +>mixin(a1, b1) : { b: number; a: boolean; } >mixin : (one: T, two: U) => { ...T; ...U } >a1 : A1 >b1 : B1 diff --git a/tests/baselines/reference/variableDeclarationInStrictMode1.errors.txt b/tests/baselines/reference/variableDeclarationInStrictMode1.errors.txt index 9dd9a8d41a1..46782aaa1d6 100644 --- a/tests/baselines/reference/variableDeclarationInStrictMode1.errors.txt +++ b/tests/baselines/reference/variableDeclarationInStrictMode1.errors.txt @@ -1,4 +1,4 @@ -lib.d.ts(28,18): error TS2300: Duplicate identifier 'eval'. +lib.d.ts(32,18): error TS2300: Duplicate identifier 'eval'. tests/cases/compiler/variableDeclarationInStrictMode1.ts(2,5): error TS1100: Invalid use of 'eval' in strict mode. tests/cases/compiler/variableDeclarationInStrictMode1.ts(2,5): error TS2300: Duplicate identifier 'eval'.