-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Discriminate partial inferences if not complete enough to satisfy con…
…straint
- Loading branch information
Showing
5 changed files
with
149 additions
and
1 deletion.
There are no files selected for viewing
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
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,13 @@ | ||
//// [typeInferenceOnIndexUnion.ts] | ||
type Options = { k: "a", a: number } | { k: "b", b: string }; | ||
declare function f<T extends Options>(p: T["k"]): T; | ||
const x = f("a"); // expect it to be `{ k: "a", a: number }` | ||
|
||
type Options2 = { k: "a", a: number, c: {} } | { k: "b", b: string, c: {} }; | ||
declare function f2<T extends Options2>(p: T["k"], c: T["c"]): T; | ||
const x2 = f2("a", { x: 1, y: 2 }); // expect it to be `{ k: "a", a: number, c: {x: number, y: number} }` | ||
|
||
|
||
//// [typeInferenceOnIndexUnion.js] | ||
var x = f("a"); // expect it to be `{ k: "a", a: number }` | ||
var x2 = f2("a", { x: 1, y: 2 }); // expect it to be `{ k: "a", a: number, c: {x: number, y: number} }` |
45 changes: 45 additions & 0 deletions
45
tests/baselines/reference/typeInferenceOnIndexUnion.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,45 @@ | ||
=== tests/cases/compiler/typeInferenceOnIndexUnion.ts === | ||
type Options = { k: "a", a: number } | { k: "b", b: string }; | ||
>Options : Symbol(Options, Decl(typeInferenceOnIndexUnion.ts, 0, 0)) | ||
>k : Symbol(k, Decl(typeInferenceOnIndexUnion.ts, 0, 16)) | ||
>a : Symbol(a, Decl(typeInferenceOnIndexUnion.ts, 0, 24)) | ||
>k : Symbol(k, Decl(typeInferenceOnIndexUnion.ts, 0, 40)) | ||
>b : Symbol(b, Decl(typeInferenceOnIndexUnion.ts, 0, 48)) | ||
|
||
declare function f<T extends Options>(p: T["k"]): T; | ||
>f : Symbol(f, Decl(typeInferenceOnIndexUnion.ts, 0, 61)) | ||
>T : Symbol(T, Decl(typeInferenceOnIndexUnion.ts, 1, 19)) | ||
>Options : Symbol(Options, Decl(typeInferenceOnIndexUnion.ts, 0, 0)) | ||
>p : Symbol(p, Decl(typeInferenceOnIndexUnion.ts, 1, 38)) | ||
>T : Symbol(T, Decl(typeInferenceOnIndexUnion.ts, 1, 19)) | ||
>T : Symbol(T, Decl(typeInferenceOnIndexUnion.ts, 1, 19)) | ||
|
||
const x = f("a"); // expect it to be `{ k: "a", a: number }` | ||
>x : Symbol(x, Decl(typeInferenceOnIndexUnion.ts, 2, 5)) | ||
>f : Symbol(f, Decl(typeInferenceOnIndexUnion.ts, 0, 61)) | ||
|
||
type Options2 = { k: "a", a: number, c: {} } | { k: "b", b: string, c: {} }; | ||
>Options2 : Symbol(Options2, Decl(typeInferenceOnIndexUnion.ts, 2, 17)) | ||
>k : Symbol(k, Decl(typeInferenceOnIndexUnion.ts, 4, 17)) | ||
>a : Symbol(a, Decl(typeInferenceOnIndexUnion.ts, 4, 25)) | ||
>c : Symbol(c, Decl(typeInferenceOnIndexUnion.ts, 4, 36)) | ||
>k : Symbol(k, Decl(typeInferenceOnIndexUnion.ts, 4, 48)) | ||
>b : Symbol(b, Decl(typeInferenceOnIndexUnion.ts, 4, 56)) | ||
>c : Symbol(c, Decl(typeInferenceOnIndexUnion.ts, 4, 67)) | ||
|
||
declare function f2<T extends Options2>(p: T["k"], c: T["c"]): T; | ||
>f2 : Symbol(f2, Decl(typeInferenceOnIndexUnion.ts, 4, 76)) | ||
>T : Symbol(T, Decl(typeInferenceOnIndexUnion.ts, 5, 20)) | ||
>Options2 : Symbol(Options2, Decl(typeInferenceOnIndexUnion.ts, 2, 17)) | ||
>p : Symbol(p, Decl(typeInferenceOnIndexUnion.ts, 5, 40)) | ||
>T : Symbol(T, Decl(typeInferenceOnIndexUnion.ts, 5, 20)) | ||
>c : Symbol(c, Decl(typeInferenceOnIndexUnion.ts, 5, 50)) | ||
>T : Symbol(T, Decl(typeInferenceOnIndexUnion.ts, 5, 20)) | ||
>T : Symbol(T, Decl(typeInferenceOnIndexUnion.ts, 5, 20)) | ||
|
||
const x2 = f2("a", { x: 1, y: 2 }); // expect it to be `{ k: "a", a: number, c: {x: number, y: number} }` | ||
>x2 : Symbol(x2, Decl(typeInferenceOnIndexUnion.ts, 6, 5)) | ||
>f2 : Symbol(f2, Decl(typeInferenceOnIndexUnion.ts, 4, 76)) | ||
>x : Symbol(x, Decl(typeInferenceOnIndexUnion.ts, 6, 20)) | ||
>y : Symbol(y, Decl(typeInferenceOnIndexUnion.ts, 6, 26)) | ||
|
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,52 @@ | ||
=== tests/cases/compiler/typeInferenceOnIndexUnion.ts === | ||
type Options = { k: "a", a: number } | { k: "b", b: string }; | ||
>Options : Options | ||
>k : "a" | ||
>a : number | ||
>k : "b" | ||
>b : string | ||
|
||
declare function f<T extends Options>(p: T["k"]): T; | ||
>f : <T extends Options>(p: T["k"]) => T | ||
>T : T | ||
>Options : Options | ||
>p : T["k"] | ||
>T : T | ||
>T : T | ||
|
||
const x = f("a"); // expect it to be `{ k: "a", a: number }` | ||
>x : { k: "a"; a: number; } | ||
>f("a") : { k: "a"; a: number; } | ||
>f : <T extends Options>(p: T["k"]) => T | ||
>"a" : "a" | ||
|
||
type Options2 = { k: "a", a: number, c: {} } | { k: "b", b: string, c: {} }; | ||
>Options2 : Options2 | ||
>k : "a" | ||
>a : number | ||
>c : {} | ||
>k : "b" | ||
>b : string | ||
>c : {} | ||
|
||
declare function f2<T extends Options2>(p: T["k"], c: T["c"]): T; | ||
>f2 : <T extends Options2>(p: T["k"], c: T["c"]) => T | ||
>T : T | ||
>Options2 : Options2 | ||
>p : T["k"] | ||
>T : T | ||
>c : T["c"] | ||
>T : T | ||
>T : T | ||
|
||
const x2 = f2("a", { x: 1, y: 2 }); // expect it to be `{ k: "a", a: number, c: {x: number, y: number} }` | ||
>x2 : { k: "a"; c: { x: number; y: number; }; a: number; } | ||
>f2("a", { x: 1, y: 2 }) : { k: "a"; c: { x: number; y: number; }; a: number; } | ||
>f2 : <T extends Options2>(p: T["k"], c: T["c"]) => T | ||
>"a" : "a" | ||
>{ x: 1, y: 2 } : { x: number; y: number; } | ||
>x : number | ||
>1 : 1 | ||
>y : number | ||
>2 : 2 | ||
|
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,7 @@ | ||
type Options = { k: "a", a: number } | { k: "b", b: string }; | ||
declare function f<T extends Options>(p: T["k"]): T; | ||
const x = f("a"); // expect it to be `{ k: "a", a: number }` | ||
|
||
type Options2 = { k: "a", a: number, c: {} } | { k: "b", b: string, c: {} }; | ||
declare function f2<T extends Options2>(p: T["k"], c: T["c"]): T; | ||
const x2 = f2("a", { x: 1, y: 2 }); // expect it to be `{ k: "a", a: number, c: {x: number, y: number} }` |