-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Distribute indexes of indexed access types first (#27243)
- Loading branch information
Showing
6 changed files
with
154 additions
and
6 deletions.
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
25 changes: 25 additions & 0 deletions
25
tests/baselines/reference/contextualTypeOfIndexedAccessParameter.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,25 @@ | ||
//// [contextualTypeOfIndexedAccessParameter.ts] | ||
type Keys = "a" | "b"; | ||
|
||
type OptionsForKey = { a: { cb: (p: number) => number } } & { b: {} }; | ||
|
||
declare function f<K extends Keys>(key: K, options: OptionsForKey[K]): void; | ||
|
||
f("a", { | ||
cb: p => p, | ||
}); | ||
|
||
function g< | ||
K extends "a" | "b">(x: ({ a: string } & { b: string })[K], y: string) { | ||
x = y; | ||
} | ||
|
||
|
||
//// [contextualTypeOfIndexedAccessParameter.js] | ||
"use strict"; | ||
f("a", { | ||
cb: function (p) { return p; } | ||
}); | ||
function g(x, y) { | ||
x = y; | ||
} |
47 changes: 47 additions & 0 deletions
47
tests/baselines/reference/contextualTypeOfIndexedAccessParameter.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,47 @@ | ||
=== tests/cases/compiler/contextualTypeOfIndexedAccessParameter.ts === | ||
type Keys = "a" | "b"; | ||
>Keys : Symbol(Keys, Decl(contextualTypeOfIndexedAccessParameter.ts, 0, 0)) | ||
|
||
type OptionsForKey = { a: { cb: (p: number) => number } } & { b: {} }; | ||
>OptionsForKey : Symbol(OptionsForKey, Decl(contextualTypeOfIndexedAccessParameter.ts, 0, 22)) | ||
>a : Symbol(a, Decl(contextualTypeOfIndexedAccessParameter.ts, 2, 22)) | ||
>cb : Symbol(cb, Decl(contextualTypeOfIndexedAccessParameter.ts, 2, 27)) | ||
>p : Symbol(p, Decl(contextualTypeOfIndexedAccessParameter.ts, 2, 33)) | ||
>b : Symbol(b, Decl(contextualTypeOfIndexedAccessParameter.ts, 2, 61)) | ||
|
||
declare function f<K extends Keys>(key: K, options: OptionsForKey[K]): void; | ||
>f : Symbol(f, Decl(contextualTypeOfIndexedAccessParameter.ts, 2, 70)) | ||
>K : Symbol(K, Decl(contextualTypeOfIndexedAccessParameter.ts, 4, 19)) | ||
>Keys : Symbol(Keys, Decl(contextualTypeOfIndexedAccessParameter.ts, 0, 0)) | ||
>key : Symbol(key, Decl(contextualTypeOfIndexedAccessParameter.ts, 4, 35)) | ||
>K : Symbol(K, Decl(contextualTypeOfIndexedAccessParameter.ts, 4, 19)) | ||
>options : Symbol(options, Decl(contextualTypeOfIndexedAccessParameter.ts, 4, 42)) | ||
>OptionsForKey : Symbol(OptionsForKey, Decl(contextualTypeOfIndexedAccessParameter.ts, 0, 22)) | ||
>K : Symbol(K, Decl(contextualTypeOfIndexedAccessParameter.ts, 4, 19)) | ||
|
||
f("a", { | ||
>f : Symbol(f, Decl(contextualTypeOfIndexedAccessParameter.ts, 2, 70)) | ||
|
||
cb: p => p, | ||
>cb : Symbol(cb, Decl(contextualTypeOfIndexedAccessParameter.ts, 6, 8)) | ||
>p : Symbol(p, Decl(contextualTypeOfIndexedAccessParameter.ts, 7, 7)) | ||
>p : Symbol(p, Decl(contextualTypeOfIndexedAccessParameter.ts, 7, 7)) | ||
|
||
}); | ||
|
||
function g< | ||
>g : Symbol(g, Decl(contextualTypeOfIndexedAccessParameter.ts, 8, 3)) | ||
|
||
K extends "a" | "b">(x: ({ a: string } & { b: string })[K], y: string) { | ||
>K : Symbol(K, Decl(contextualTypeOfIndexedAccessParameter.ts, 10, 11)) | ||
>x : Symbol(x, Decl(contextualTypeOfIndexedAccessParameter.ts, 11, 25)) | ||
>a : Symbol(a, Decl(contextualTypeOfIndexedAccessParameter.ts, 11, 30)) | ||
>b : Symbol(b, Decl(contextualTypeOfIndexedAccessParameter.ts, 11, 46)) | ||
>K : Symbol(K, Decl(contextualTypeOfIndexedAccessParameter.ts, 10, 11)) | ||
>y : Symbol(y, Decl(contextualTypeOfIndexedAccessParameter.ts, 11, 63)) | ||
|
||
x = y; | ||
>x : Symbol(x, Decl(contextualTypeOfIndexedAccessParameter.ts, 11, 25)) | ||
>y : Symbol(y, Decl(contextualTypeOfIndexedAccessParameter.ts, 11, 63)) | ||
} | ||
|
45 changes: 45 additions & 0 deletions
45
tests/baselines/reference/contextualTypeOfIndexedAccessParameter.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,45 @@ | ||
=== tests/cases/compiler/contextualTypeOfIndexedAccessParameter.ts === | ||
type Keys = "a" | "b"; | ||
>Keys : Keys | ||
|
||
type OptionsForKey = { a: { cb: (p: number) => number } } & { b: {} }; | ||
>OptionsForKey : OptionsForKey | ||
>a : { cb: (p: number) => number; } | ||
>cb : (p: number) => number | ||
>p : number | ||
>b : {} | ||
|
||
declare function f<K extends Keys>(key: K, options: OptionsForKey[K]): void; | ||
>f : <K extends Keys>(key: K, options: OptionsForKey[K]) => void | ||
>key : K | ||
>options : OptionsForKey[K] | ||
|
||
f("a", { | ||
>f("a", { cb: p => p,}) : void | ||
>f : <K extends Keys>(key: K, options: OptionsForKey[K]) => void | ||
>"a" : "a" | ||
>{ cb: p => p,} : { cb: (p: number) => number; } | ||
|
||
cb: p => p, | ||
>cb : (p: number) => number | ||
>p => p : (p: number) => number | ||
>p : number | ||
>p : number | ||
|
||
}); | ||
|
||
function g< | ||
>g : <K extends Keys>(x: ({ a: string; } & { b: string; })[K], y: string) => void | ||
|
||
K extends "a" | "b">(x: ({ a: string } & { b: string })[K], y: string) { | ||
>x : ({ a: string; } & { b: string; })[K] | ||
>a : string | ||
>b : string | ||
>y : string | ||
|
||
x = y; | ||
>x = y : string | ||
>x : ({ a: string; } & { b: string; })[K] | ||
>y : string | ||
} | ||
|
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
15 changes: 15 additions & 0 deletions
15
tests/cases/compiler/contextualTypeOfIndexedAccessParameter.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,15 @@ | ||
// @strict: true | ||
type Keys = "a" | "b"; | ||
|
||
type OptionsForKey = { a: { cb: (p: number) => number } } & { b: {} }; | ||
|
||
declare function f<K extends Keys>(key: K, options: OptionsForKey[K]): void; | ||
|
||
f("a", { | ||
cb: p => p, | ||
}); | ||
|
||
function g< | ||
K extends "a" | "b">(x: ({ a: string } & { b: string })[K], y: string) { | ||
x = y; | ||
} |