Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9551e67
commit e76b422
Showing
5 changed files
with
271 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
tests/baselines/reference/indirectDiscriminantAndExcessProperty.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
50
tests/baselines/reference/indirectDiscriminantAndExcessProperty.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}); |
71 changes: 71 additions & 0 deletions
71
tests/baselines/reference/indirectDiscriminantAndExcessProperty.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
|
||
}); | ||
|
84 changes: 84 additions & 0 deletions
84
tests/baselines/reference/indirectDiscriminantAndExcessProperty.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
25
tests/cases/compiler/indirectDiscriminantAndExcessProperty.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}); |