Skip to content

Commit

Permalink
Add a test per request
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanCavanaugh committed Jul 26, 2023
1 parent 9551e67 commit e76b422
Show file tree
Hide file tree
Showing 5 changed files with 271 additions and 0 deletions.
@@ -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,
});

50 changes: 50 additions & 0 deletions 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,
});
@@ -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))

});

@@ -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

});

25 changes: 25 additions & 0 deletions 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,
});

0 comments on commit e76b422

Please sign in to comment.