From e76b422ae702b7e54a0cc05f88dd402b8426c3bc Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 26 Jul 2023 14:15:41 -0700 Subject: [PATCH] Add a test per request --- ...ctDiscriminantAndExcessProperty.errors.txt | 41 +++++++++ .../indirectDiscriminantAndExcessProperty.js | 50 +++++++++++ ...irectDiscriminantAndExcessProperty.symbols | 71 ++++++++++++++++ ...ndirectDiscriminantAndExcessProperty.types | 84 +++++++++++++++++++ .../indirectDiscriminantAndExcessProperty.ts | 25 ++++++ 5 files changed, 271 insertions(+) create mode 100644 tests/baselines/reference/indirectDiscriminantAndExcessProperty.errors.txt create mode 100644 tests/baselines/reference/indirectDiscriminantAndExcessProperty.js create mode 100644 tests/baselines/reference/indirectDiscriminantAndExcessProperty.symbols create mode 100644 tests/baselines/reference/indirectDiscriminantAndExcessProperty.types create mode 100644 tests/cases/compiler/indirectDiscriminantAndExcessProperty.ts diff --git a/tests/baselines/reference/indirectDiscriminantAndExcessProperty.errors.txt b/tests/baselines/reference/indirectDiscriminantAndExcessProperty.errors.txt new file mode 100644 index 0000000000000..b14efcd6305d0 --- /dev/null +++ b/tests/baselines/reference/indirectDiscriminantAndExcessProperty.errors.txt @@ -0,0 +1,41 @@ +indirectDiscriminantAndExcessProperty.ts(9,5): error TS2322: Type 'string' is not assignable to type '"foo" | "bar"'. +indirectDiscriminantAndExcessProperty.ts(15,5): error TS2322: Type 'string' is not assignable to type '"foo" | "bar"'. +indirectDiscriminantAndExcessProperty.ts(22,5): error TS2322: Type 'string' is not assignable to type '"foo" | "bar"'. + + +==== indirectDiscriminantAndExcessProperty.ts (3 errors) ==== + export type Blah = + | { type: "foo", abc: string } + | { type: "bar", xyz: number, extra: any }; + + declare function thing(blah: Blah): void; + + let foo1 = "foo"; + thing({ + type: foo1, + ~~~~ +!!! error TS2322: Type 'string' is not assignable to type '"foo" | "bar"'. +!!! related TS6500 indirectDiscriminantAndExcessProperty.ts:2:9: The expected type comes from property 'type' which is declared here on type 'Blah' + abc: "hello!" + }); + + let foo2 = "foo"; + thing({ + type: foo2, + ~~~~ +!!! error TS2322: Type 'string' is not assignable to type '"foo" | "bar"'. +!!! related TS6500 indirectDiscriminantAndExcessProperty.ts:2:9: The expected type comes from property 'type' which is declared here on type 'Blah' + abc: "hello!", + extra: 123, + }); + + let bar = "bar"; + thing({ + type: bar, + ~~~~ +!!! error TS2322: Type 'string' is not assignable to type '"foo" | "bar"'. +!!! related TS6500 indirectDiscriminantAndExcessProperty.ts:2:9: The expected type comes from property 'type' which is declared here on type 'Blah' + xyz: 123, + extra: 123, + }); + \ No newline at end of file diff --git a/tests/baselines/reference/indirectDiscriminantAndExcessProperty.js b/tests/baselines/reference/indirectDiscriminantAndExcessProperty.js new file mode 100644 index 0000000000000..b506b5750ab46 --- /dev/null +++ b/tests/baselines/reference/indirectDiscriminantAndExcessProperty.js @@ -0,0 +1,50 @@ +//// [tests/cases/compiler/indirectDiscriminantAndExcessProperty.ts] //// + +//// [indirectDiscriminantAndExcessProperty.ts] +export type Blah = + | { type: "foo", abc: string } + | { type: "bar", xyz: number, extra: any }; + +declare function thing(blah: Blah): void; + +let foo1 = "foo"; +thing({ + type: foo1, + abc: "hello!" +}); + +let foo2 = "foo"; +thing({ + type: foo2, + abc: "hello!", + extra: 123, +}); + +let bar = "bar"; +thing({ + type: bar, + xyz: 123, + extra: 123, +}); + + +//// [indirectDiscriminantAndExcessProperty.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var foo1 = "foo"; +thing({ + type: foo1, + abc: "hello!" +}); +var foo2 = "foo"; +thing({ + type: foo2, + abc: "hello!", + extra: 123, +}); +var bar = "bar"; +thing({ + type: bar, + xyz: 123, + extra: 123, +}); diff --git a/tests/baselines/reference/indirectDiscriminantAndExcessProperty.symbols b/tests/baselines/reference/indirectDiscriminantAndExcessProperty.symbols new file mode 100644 index 0000000000000..15cb41dc4d747 --- /dev/null +++ b/tests/baselines/reference/indirectDiscriminantAndExcessProperty.symbols @@ -0,0 +1,71 @@ +//// [tests/cases/compiler/indirectDiscriminantAndExcessProperty.ts] //// + +=== indirectDiscriminantAndExcessProperty.ts === +export type Blah = +>Blah : Symbol(Blah, Decl(indirectDiscriminantAndExcessProperty.ts, 0, 0)) + + | { type: "foo", abc: string } +>type : Symbol(type, Decl(indirectDiscriminantAndExcessProperty.ts, 1, 7)) +>abc : Symbol(abc, Decl(indirectDiscriminantAndExcessProperty.ts, 1, 20)) + + | { type: "bar", xyz: number, extra: any }; +>type : Symbol(type, Decl(indirectDiscriminantAndExcessProperty.ts, 2, 7)) +>xyz : Symbol(xyz, Decl(indirectDiscriminantAndExcessProperty.ts, 2, 20)) +>extra : Symbol(extra, Decl(indirectDiscriminantAndExcessProperty.ts, 2, 33)) + +declare function thing(blah: Blah): void; +>thing : Symbol(thing, Decl(indirectDiscriminantAndExcessProperty.ts, 2, 47)) +>blah : Symbol(blah, Decl(indirectDiscriminantAndExcessProperty.ts, 4, 23)) +>Blah : Symbol(Blah, Decl(indirectDiscriminantAndExcessProperty.ts, 0, 0)) + +let foo1 = "foo"; +>foo1 : Symbol(foo1, Decl(indirectDiscriminantAndExcessProperty.ts, 6, 3)) + +thing({ +>thing : Symbol(thing, Decl(indirectDiscriminantAndExcessProperty.ts, 2, 47)) + + type: foo1, +>type : Symbol(type, Decl(indirectDiscriminantAndExcessProperty.ts, 7, 7)) +>foo1 : Symbol(foo1, Decl(indirectDiscriminantAndExcessProperty.ts, 6, 3)) + + abc: "hello!" +>abc : Symbol(abc, Decl(indirectDiscriminantAndExcessProperty.ts, 8, 15)) + +}); + +let foo2 = "foo"; +>foo2 : Symbol(foo2, Decl(indirectDiscriminantAndExcessProperty.ts, 12, 3)) + +thing({ +>thing : Symbol(thing, Decl(indirectDiscriminantAndExcessProperty.ts, 2, 47)) + + type: foo2, +>type : Symbol(type, Decl(indirectDiscriminantAndExcessProperty.ts, 13, 7)) +>foo2 : Symbol(foo2, Decl(indirectDiscriminantAndExcessProperty.ts, 12, 3)) + + abc: "hello!", +>abc : Symbol(abc, Decl(indirectDiscriminantAndExcessProperty.ts, 14, 15)) + + extra: 123, +>extra : Symbol(extra, Decl(indirectDiscriminantAndExcessProperty.ts, 15, 18)) + +}); + +let bar = "bar"; +>bar : Symbol(bar, Decl(indirectDiscriminantAndExcessProperty.ts, 19, 3)) + +thing({ +>thing : Symbol(thing, Decl(indirectDiscriminantAndExcessProperty.ts, 2, 47)) + + type: bar, +>type : Symbol(type, Decl(indirectDiscriminantAndExcessProperty.ts, 20, 7)) +>bar : Symbol(bar, Decl(indirectDiscriminantAndExcessProperty.ts, 19, 3)) + + xyz: 123, +>xyz : Symbol(xyz, Decl(indirectDiscriminantAndExcessProperty.ts, 21, 14)) + + extra: 123, +>extra : Symbol(extra, Decl(indirectDiscriminantAndExcessProperty.ts, 22, 13)) + +}); + diff --git a/tests/baselines/reference/indirectDiscriminantAndExcessProperty.types b/tests/baselines/reference/indirectDiscriminantAndExcessProperty.types new file mode 100644 index 0000000000000..491d0be152850 --- /dev/null +++ b/tests/baselines/reference/indirectDiscriminantAndExcessProperty.types @@ -0,0 +1,84 @@ +//// [tests/cases/compiler/indirectDiscriminantAndExcessProperty.ts] //// + +=== indirectDiscriminantAndExcessProperty.ts === +export type Blah = +>Blah : { type: "foo"; abc: string; } | { type: "bar"; xyz: number; extra: any; } + + | { type: "foo", abc: string } +>type : "foo" +>abc : string + + | { type: "bar", xyz: number, extra: any }; +>type : "bar" +>xyz : number +>extra : any + +declare function thing(blah: Blah): void; +>thing : (blah: Blah) => void +>blah : Blah + +let foo1 = "foo"; +>foo1 : string +>"foo" : "foo" + +thing({ +>thing({ type: foo1, abc: "hello!"}) : void +>thing : (blah: Blah) => void +>{ type: foo1, abc: "hello!"} : { type: string; abc: string; } + + type: foo1, +>type : string +>foo1 : string + + abc: "hello!" +>abc : string +>"hello!" : "hello!" + +}); + +let foo2 = "foo"; +>foo2 : string +>"foo" : "foo" + +thing({ +>thing({ type: foo2, abc: "hello!", extra: 123,}) : void +>thing : (blah: Blah) => void +>{ type: foo2, abc: "hello!", extra: 123,} : { type: string; abc: string; extra: number; } + + type: foo2, +>type : string +>foo2 : string + + abc: "hello!", +>abc : string +>"hello!" : "hello!" + + extra: 123, +>extra : number +>123 : 123 + +}); + +let bar = "bar"; +>bar : string +>"bar" : "bar" + +thing({ +>thing({ type: bar, xyz: 123, extra: 123,}) : void +>thing : (blah: Blah) => void +>{ type: bar, xyz: 123, extra: 123,} : { type: string; xyz: number; extra: number; } + + type: bar, +>type : string +>bar : string + + xyz: 123, +>xyz : number +>123 : 123 + + extra: 123, +>extra : number +>123 : 123 + +}); + diff --git a/tests/cases/compiler/indirectDiscriminantAndExcessProperty.ts b/tests/cases/compiler/indirectDiscriminantAndExcessProperty.ts new file mode 100644 index 0000000000000..a495b5768bbac --- /dev/null +++ b/tests/cases/compiler/indirectDiscriminantAndExcessProperty.ts @@ -0,0 +1,25 @@ +export type Blah = + | { type: "foo", abc: string } + | { type: "bar", xyz: number, extra: any }; + +declare function thing(blah: Blah): void; + +let foo1 = "foo"; +thing({ + type: foo1, + abc: "hello!" +}); + +let foo2 = "foo"; +thing({ + type: foo2, + abc: "hello!", + extra: 123, +}); + +let bar = "bar"; +thing({ + type: bar, + xyz: 123, + extra: 123, +});