diff --git a/tests/baselines/reference/excessPropertyCheckWithUnions.errors.txt b/tests/baselines/reference/excessPropertyCheckWithUnions.errors.txt index efd14c3579779..8c34a0f5d69cf 100644 --- a/tests/baselines/reference/excessPropertyCheckWithUnions.errors.txt +++ b/tests/baselines/reference/excessPropertyCheckWithUnions.errors.txt @@ -192,4 +192,43 @@ tests/cases/compiler/excessPropertyCheckWithUnions.ts(114,63): error TS2322: Typ const obj2: { [x: string]: number } | { a: number } = { a: 5, c: 'abc' }; // Error ~ !!! error TS2322: Type 'string' is not assignable to type 'number'. + + // Repro from #33732 + + interface I1 { + prop1: string; + } + + interface I2 { + prop2: string; + } + + interface I3 extends Record { + + } + + type Properties = + | { [key: string]: never } + | I1 + | I2 + | I3 + ; + + + declare const prop1: string; + declare const prop2: string | undefined; + + function F1(_arg: { props: Properties }) { } + F1({ + props: { + prop1, + prop2, + }, + }); + + function F2(_props: Properties) { } + F2({ + prop1, + prop2, + }); \ No newline at end of file diff --git a/tests/baselines/reference/excessPropertyCheckWithUnions.js b/tests/baselines/reference/excessPropertyCheckWithUnions.js index 34cd337705a34..ea406ef4281a5 100644 --- a/tests/baselines/reference/excessPropertyCheckWithUnions.js +++ b/tests/baselines/reference/excessPropertyCheckWithUnions.js @@ -113,6 +113,45 @@ const dataSpecification: ObjectDataSpecification = { // Error const obj1: { [x: string]: number } | { [x: number]: number } = { a: 'abc' }; // Error const obj2: { [x: string]: number } | { a: number } = { a: 5, c: 'abc' }; // Error + +// Repro from #33732 + +interface I1 { + prop1: string; +} + +interface I2 { + prop2: string; +} + +interface I3 extends Record { + +} + +type Properties = + | { [key: string]: never } + | I1 + | I2 + | I3 + ; + + +declare const prop1: string; +declare const prop2: string | undefined; + +function F1(_arg: { props: Properties }) { } +F1({ + props: { + prop1, + prop2, + }, +}); + +function F2(_props: Properties) { } +F2({ + prop1, + prop2, +}); //// [excessPropertyCheckWithUnions.js] @@ -177,3 +216,15 @@ var dataSpecification = { // Repro from #34611 var obj1 = { a: 'abc' }; // Error var obj2 = { a: 5, c: 'abc' }; // Error +function F1(_arg) { } +F1({ + props: { + prop1: prop1, + prop2: prop2 + } +}); +function F2(_props) { } +F2({ + prop1: prop1, + prop2: prop2 +}); diff --git a/tests/baselines/reference/excessPropertyCheckWithUnions.symbols b/tests/baselines/reference/excessPropertyCheckWithUnions.symbols index 8fb86125a5731..80921fedad26c 100644 --- a/tests/baselines/reference/excessPropertyCheckWithUnions.symbols +++ b/tests/baselines/reference/excessPropertyCheckWithUnions.symbols @@ -310,3 +310,86 @@ const obj2: { [x: string]: number } | { a: number } = { a: 5, c: 'abc' }; // Er >a : Symbol(a, Decl(excessPropertyCheckWithUnions.ts, 113, 55)) >c : Symbol(c, Decl(excessPropertyCheckWithUnions.ts, 113, 61)) +// Repro from #33732 + +interface I1 { +>I1 : Symbol(I1, Decl(excessPropertyCheckWithUnions.ts, 113, 73)) + + prop1: string; +>prop1 : Symbol(I1.prop1, Decl(excessPropertyCheckWithUnions.ts, 117, 14)) +} + +interface I2 { +>I2 : Symbol(I2, Decl(excessPropertyCheckWithUnions.ts, 119, 1)) + + prop2: string; +>prop2 : Symbol(I2.prop2, Decl(excessPropertyCheckWithUnions.ts, 121, 14)) +} + +interface I3 extends Record { +>I3 : Symbol(I3, Decl(excessPropertyCheckWithUnions.ts, 123, 1)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) + +} + +type Properties = +>Properties : Symbol(Properties, Decl(excessPropertyCheckWithUnions.ts, 127, 1)) + + | { [key: string]: never } +>key : Symbol(key, Decl(excessPropertyCheckWithUnions.ts, 130, 9)) + + | I1 +>I1 : Symbol(I1, Decl(excessPropertyCheckWithUnions.ts, 113, 73)) + + | I2 +>I2 : Symbol(I2, Decl(excessPropertyCheckWithUnions.ts, 119, 1)) + + | I3 +>I3 : Symbol(I3, Decl(excessPropertyCheckWithUnions.ts, 123, 1)) + + ; + + +declare const prop1: string; +>prop1 : Symbol(prop1, Decl(excessPropertyCheckWithUnions.ts, 137, 13)) + +declare const prop2: string | undefined; +>prop2 : Symbol(prop2, Decl(excessPropertyCheckWithUnions.ts, 138, 13)) + +function F1(_arg: { props: Properties }) { } +>F1 : Symbol(F1, Decl(excessPropertyCheckWithUnions.ts, 138, 40)) +>_arg : Symbol(_arg, Decl(excessPropertyCheckWithUnions.ts, 140, 12)) +>props : Symbol(props, Decl(excessPropertyCheckWithUnions.ts, 140, 19)) +>Properties : Symbol(Properties, Decl(excessPropertyCheckWithUnions.ts, 127, 1)) + +F1({ +>F1 : Symbol(F1, Decl(excessPropertyCheckWithUnions.ts, 138, 40)) + + props: { +>props : Symbol(props, Decl(excessPropertyCheckWithUnions.ts, 141, 4)) + + prop1, +>prop1 : Symbol(prop1, Decl(excessPropertyCheckWithUnions.ts, 142, 12)) + + prop2, +>prop2 : Symbol(prop2, Decl(excessPropertyCheckWithUnions.ts, 143, 14)) + + }, +}); + +function F2(_props: Properties) { } +>F2 : Symbol(F2, Decl(excessPropertyCheckWithUnions.ts, 146, 3)) +>_props : Symbol(_props, Decl(excessPropertyCheckWithUnions.ts, 148, 12)) +>Properties : Symbol(Properties, Decl(excessPropertyCheckWithUnions.ts, 127, 1)) + +F2({ +>F2 : Symbol(F2, Decl(excessPropertyCheckWithUnions.ts, 146, 3)) + + prop1, +>prop1 : Symbol(prop1, Decl(excessPropertyCheckWithUnions.ts, 149, 4)) + + prop2, +>prop2 : Symbol(prop2, Decl(excessPropertyCheckWithUnions.ts, 150, 10)) + +}); + diff --git a/tests/baselines/reference/excessPropertyCheckWithUnions.types b/tests/baselines/reference/excessPropertyCheckWithUnions.types index 38e9a6c81e7a4..211f87c6ba627 100644 --- a/tests/baselines/reference/excessPropertyCheckWithUnions.types +++ b/tests/baselines/reference/excessPropertyCheckWithUnions.types @@ -364,3 +364,77 @@ const obj2: { [x: string]: number } | { a: number } = { a: 5, c: 'abc' }; // Er >c : string >'abc' : "abc" +// Repro from #33732 + +interface I1 { + prop1: string; +>prop1 : string +} + +interface I2 { + prop2: string; +>prop2 : string +} + +interface I3 extends Record { + +} + +type Properties = +>Properties : Properties + + | { [key: string]: never } +>key : string + + | I1 + | I2 + | I3 + ; + + +declare const prop1: string; +>prop1 : string + +declare const prop2: string | undefined; +>prop2 : string | undefined + +function F1(_arg: { props: Properties }) { } +>F1 : (_arg: { props: Properties; }) => void +>_arg : { props: Properties; } +>props : Properties + +F1({ +>F1({ props: { prop1, prop2, },}) : void +>F1 : (_arg: { props: Properties; }) => void +>{ props: { prop1, prop2, },} : { props: { prop1: string; prop2: string | undefined; }; } + + props: { +>props : { prop1: string; prop2: string | undefined; } +>{ prop1, prop2, } : { prop1: string; prop2: string | undefined; } + + prop1, +>prop1 : string + + prop2, +>prop2 : string | undefined + + }, +}); + +function F2(_props: Properties) { } +>F2 : (_props: Properties) => void +>_props : Properties + +F2({ +>F2({ prop1, prop2,}) : void +>F2 : (_props: Properties) => void +>{ prop1, prop2,} : { prop1: string; prop2: string | undefined; } + + prop1, +>prop1 : string + + prop2, +>prop2 : string | undefined + +}); + diff --git a/tests/cases/compiler/excessPropertyCheckWithUnions.ts b/tests/cases/compiler/excessPropertyCheckWithUnions.ts index 635c5c2a7d3f6..4f8ea87a3ceb2 100644 --- a/tests/cases/compiler/excessPropertyCheckWithUnions.ts +++ b/tests/cases/compiler/excessPropertyCheckWithUnions.ts @@ -113,3 +113,42 @@ const dataSpecification: ObjectDataSpecification = { // Error const obj1: { [x: string]: number } | { [x: number]: number } = { a: 'abc' }; // Error const obj2: { [x: string]: number } | { a: number } = { a: 5, c: 'abc' }; // Error + +// Repro from #33732 + +interface I1 { + prop1: string; +} + +interface I2 { + prop2: string; +} + +interface I3 extends Record { + +} + +type Properties = + | { [key: string]: never } + | I1 + | I2 + | I3 + ; + + +declare const prop1: string; +declare const prop2: string | undefined; + +function F1(_arg: { props: Properties }) { } +F1({ + props: { + prop1, + prop2, + }, +}); + +function F2(_props: Properties) { } +F2({ + prop1, + prop2, +});