-
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.
Add inference priority for mapped type keys (#22246)
* Add inference priority for mapped type keys The new priority causes union inference, similarly to return type * Rename priority * Fix comment typo
- Loading branch information
Showing
8 changed files
with
178 additions
and
15 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
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
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,34 @@ | ||
//// [mappedTypeMultiInference.ts] | ||
interface Style { | ||
flashy: any; | ||
} | ||
|
||
declare function mergeStyleSets<K extends string>( | ||
...cssSets: { [P in K]?: Style }[]): { [P in K]: Style }; | ||
|
||
// Expected: | ||
// let x: { | ||
// a: Style; | ||
// b: Style; | ||
// } | ||
let x = mergeStyleSets( | ||
{}, | ||
{ | ||
a: { flashy: true }, | ||
}, | ||
{ | ||
b: { flashy: true }, | ||
}, | ||
) | ||
|
||
//// [mappedTypeMultiInference.js] | ||
// Expected: | ||
// let x: { | ||
// a: Style; | ||
// b: Style; | ||
// } | ||
var x = mergeStyleSets({}, { | ||
a: { flashy: true } | ||
}, { | ||
b: { flashy: true } | ||
}); |
44 changes: 44 additions & 0 deletions
44
tests/baselines/reference/mappedTypeMultiInference.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,44 @@ | ||
=== tests/cases/compiler/mappedTypeMultiInference.ts === | ||
interface Style { | ||
>Style : Symbol(Style, Decl(mappedTypeMultiInference.ts, 0, 0)) | ||
|
||
flashy: any; | ||
>flashy : Symbol(Style.flashy, Decl(mappedTypeMultiInference.ts, 0, 17)) | ||
} | ||
|
||
declare function mergeStyleSets<K extends string>( | ||
>mergeStyleSets : Symbol(mergeStyleSets, Decl(mappedTypeMultiInference.ts, 2, 1)) | ||
>K : Symbol(K, Decl(mappedTypeMultiInference.ts, 4, 32)) | ||
|
||
...cssSets: { [P in K]?: Style }[]): { [P in K]: Style }; | ||
>cssSets : Symbol(cssSets, Decl(mappedTypeMultiInference.ts, 4, 50)) | ||
>P : Symbol(P, Decl(mappedTypeMultiInference.ts, 5, 19)) | ||
>K : Symbol(K, Decl(mappedTypeMultiInference.ts, 4, 32)) | ||
>Style : Symbol(Style, Decl(mappedTypeMultiInference.ts, 0, 0)) | ||
>P : Symbol(P, Decl(mappedTypeMultiInference.ts, 5, 44)) | ||
>K : Symbol(K, Decl(mappedTypeMultiInference.ts, 4, 32)) | ||
>Style : Symbol(Style, Decl(mappedTypeMultiInference.ts, 0, 0)) | ||
|
||
// Expected: | ||
// let x: { | ||
// a: Style; | ||
// b: Style; | ||
// } | ||
let x = mergeStyleSets( | ||
>x : Symbol(x, Decl(mappedTypeMultiInference.ts, 12, 3)) | ||
>mergeStyleSets : Symbol(mergeStyleSets, Decl(mappedTypeMultiInference.ts, 2, 1)) | ||
|
||
{}, | ||
{ | ||
a: { flashy: true }, | ||
>a : Symbol(a, Decl(mappedTypeMultiInference.ts, 14, 5)) | ||
>flashy : Symbol(flashy, Decl(mappedTypeMultiInference.ts, 15, 12)) | ||
|
||
}, | ||
{ | ||
b: { flashy: true }, | ||
>b : Symbol(b, Decl(mappedTypeMultiInference.ts, 17, 5)) | ||
>flashy : Symbol(flashy, Decl(mappedTypeMultiInference.ts, 18, 12)) | ||
|
||
}, | ||
) |
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,54 @@ | ||
=== tests/cases/compiler/mappedTypeMultiInference.ts === | ||
interface Style { | ||
>Style : Style | ||
|
||
flashy: any; | ||
>flashy : any | ||
} | ||
|
||
declare function mergeStyleSets<K extends string>( | ||
>mergeStyleSets : <K extends string>(...cssSets: { [P in K]?: Style; }[]) => { [P in K]: Style; } | ||
>K : K | ||
|
||
...cssSets: { [P in K]?: Style }[]): { [P in K]: Style }; | ||
>cssSets : { [P in K]?: Style; }[] | ||
>P : P | ||
>K : K | ||
>Style : Style | ||
>P : P | ||
>K : K | ||
>Style : Style | ||
|
||
// Expected: | ||
// let x: { | ||
// a: Style; | ||
// b: Style; | ||
// } | ||
let x = mergeStyleSets( | ||
>x : { a: Style; b: Style; } | ||
>mergeStyleSets( {}, { a: { flashy: true }, }, { b: { flashy: true }, },) : { a: Style; b: Style; } | ||
>mergeStyleSets : <K extends string>(...cssSets: { [P in K]?: Style; }[]) => { [P in K]: Style; } | ||
|
||
{}, | ||
>{} : {} | ||
{ | ||
>{ a: { flashy: true }, } : { a: { flashy: boolean; }; } | ||
|
||
a: { flashy: true }, | ||
>a : { flashy: boolean; } | ||
>{ flashy: true } : { flashy: boolean; } | ||
>flashy : boolean | ||
>true : true | ||
|
||
}, | ||
{ | ||
>{ b: { flashy: true }, } : { b: { flashy: boolean; }; } | ||
|
||
b: { flashy: true }, | ||
>b : { flashy: boolean; } | ||
>{ flashy: true } : { flashy: boolean; } | ||
>flashy : boolean | ||
>true : true | ||
|
||
}, | ||
) |
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,21 @@ | ||
interface Style { | ||
flashy: any; | ||
} | ||
|
||
declare function mergeStyleSets<K extends string>( | ||
...cssSets: { [P in K]?: Style }[]): { [P in K]: Style }; | ||
|
||
// Expected: | ||
// let x: { | ||
// a: Style; | ||
// b: Style; | ||
// } | ||
let x = mergeStyleSets( | ||
{}, | ||
{ | ||
a: { flashy: true }, | ||
}, | ||
{ | ||
b: { flashy: true }, | ||
}, | ||
) |