-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Fixed regression in reverse mapped type inference caused by cache leak #59232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gabritto
merged 7 commits into
microsoft:main
from
Andarist:fix/reverse-mapped-inference-same-source
Jul 12, 2024
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
70fc23c
Fixed regression in reverse mapped type inference caused by cache leak
Andarist aa5c89e
use separate caches
Andarist 21dfd9c
Merge remote-tracking branch 'origin/main' into fix/reverse-mapped-in…
Andarist 65afa2a
limit printing of deeply nested reverse mapped type properties
gabritto b49f97f
Merge branch 'fix/reverse-mapped-inference-same-source' of https://gi…
gabritto 05c66d4
update baseline
gabritto c1a1e6a
remove redundant comment from the test case
Andarist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
116 changes: 116 additions & 0 deletions
116
tests/baselines/reference/reverseMappedTypeInferenceSameSource1.symbols
This file contains hidden or 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,116 @@ | ||
| //// [tests/cases/compiler/reverseMappedTypeInferenceSameSource1.ts] //// | ||
|
|
||
| === reverseMappedTypeInferenceSameSource1.ts === | ||
| type Action<T extends string = string> = { | ||
| >Action : Symbol(Action, Decl(reverseMappedTypeInferenceSameSource1.ts, 0, 0)) | ||
| >T : Symbol(T, Decl(reverseMappedTypeInferenceSameSource1.ts, 0, 12)) | ||
|
|
||
| type: T; | ||
| >type : Symbol(type, Decl(reverseMappedTypeInferenceSameSource1.ts, 0, 42)) | ||
| >T : Symbol(T, Decl(reverseMappedTypeInferenceSameSource1.ts, 0, 12)) | ||
|
|
||
| }; | ||
| interface UnknownAction extends Action { | ||
| >UnknownAction : Symbol(UnknownAction, Decl(reverseMappedTypeInferenceSameSource1.ts, 2, 2)) | ||
| >Action : Symbol(Action, Decl(reverseMappedTypeInferenceSameSource1.ts, 0, 0)) | ||
|
|
||
| [extraProps: string]: unknown; | ||
| >extraProps : Symbol(extraProps, Decl(reverseMappedTypeInferenceSameSource1.ts, 4, 3)) | ||
| } | ||
| type Reducer<S = any, A extends Action = UnknownAction> = ( | ||
| >Reducer : Symbol(Reducer, Decl(reverseMappedTypeInferenceSameSource1.ts, 5, 1)) | ||
| >S : Symbol(S, Decl(reverseMappedTypeInferenceSameSource1.ts, 6, 13)) | ||
| >A : Symbol(A, Decl(reverseMappedTypeInferenceSameSource1.ts, 6, 21)) | ||
| >Action : Symbol(Action, Decl(reverseMappedTypeInferenceSameSource1.ts, 0, 0)) | ||
| >UnknownAction : Symbol(UnknownAction, Decl(reverseMappedTypeInferenceSameSource1.ts, 2, 2)) | ||
|
|
||
| state: S | undefined, | ||
| >state : Symbol(state, Decl(reverseMappedTypeInferenceSameSource1.ts, 6, 59)) | ||
| >S : Symbol(S, Decl(reverseMappedTypeInferenceSameSource1.ts, 6, 13)) | ||
|
|
||
| action: A, | ||
| >action : Symbol(action, Decl(reverseMappedTypeInferenceSameSource1.ts, 7, 23)) | ||
| >A : Symbol(A, Decl(reverseMappedTypeInferenceSameSource1.ts, 6, 21)) | ||
|
|
||
| ) => S; | ||
| >S : Symbol(S, Decl(reverseMappedTypeInferenceSameSource1.ts, 6, 13)) | ||
|
|
||
| type ReducersMapObject<S = any, A extends Action = UnknownAction> = { | ||
| >ReducersMapObject : Symbol(ReducersMapObject, Decl(reverseMappedTypeInferenceSameSource1.ts, 9, 7)) | ||
| >S : Symbol(S, Decl(reverseMappedTypeInferenceSameSource1.ts, 11, 23)) | ||
| >A : Symbol(A, Decl(reverseMappedTypeInferenceSameSource1.ts, 11, 31)) | ||
| >Action : Symbol(Action, Decl(reverseMappedTypeInferenceSameSource1.ts, 0, 0)) | ||
| >UnknownAction : Symbol(UnknownAction, Decl(reverseMappedTypeInferenceSameSource1.ts, 2, 2)) | ||
|
|
||
| [K in keyof S]: Reducer<S[K], A>; | ||
| >K : Symbol(K, Decl(reverseMappedTypeInferenceSameSource1.ts, 12, 3)) | ||
| >S : Symbol(S, Decl(reverseMappedTypeInferenceSameSource1.ts, 11, 23)) | ||
| >Reducer : Symbol(Reducer, Decl(reverseMappedTypeInferenceSameSource1.ts, 5, 1)) | ||
| >S : Symbol(S, Decl(reverseMappedTypeInferenceSameSource1.ts, 11, 23)) | ||
| >K : Symbol(K, Decl(reverseMappedTypeInferenceSameSource1.ts, 12, 3)) | ||
| >A : Symbol(A, Decl(reverseMappedTypeInferenceSameSource1.ts, 11, 31)) | ||
|
|
||
| }; | ||
|
|
||
| interface ConfigureStoreOptions<S = any, A extends Action = UnknownAction> { | ||
| >ConfigureStoreOptions : Symbol(ConfigureStoreOptions, Decl(reverseMappedTypeInferenceSameSource1.ts, 13, 2)) | ||
| >S : Symbol(S, Decl(reverseMappedTypeInferenceSameSource1.ts, 15, 32)) | ||
| >A : Symbol(A, Decl(reverseMappedTypeInferenceSameSource1.ts, 15, 40)) | ||
| >Action : Symbol(Action, Decl(reverseMappedTypeInferenceSameSource1.ts, 0, 0)) | ||
| >UnknownAction : Symbol(UnknownAction, Decl(reverseMappedTypeInferenceSameSource1.ts, 2, 2)) | ||
|
|
||
| reducer: Reducer<S, A> | ReducersMapObject<S, A>; | ||
| >reducer : Symbol(ConfigureStoreOptions.reducer, Decl(reverseMappedTypeInferenceSameSource1.ts, 15, 76)) | ||
| >Reducer : Symbol(Reducer, Decl(reverseMappedTypeInferenceSameSource1.ts, 5, 1)) | ||
| >S : Symbol(S, Decl(reverseMappedTypeInferenceSameSource1.ts, 15, 32)) | ||
| >A : Symbol(A, Decl(reverseMappedTypeInferenceSameSource1.ts, 15, 40)) | ||
| >ReducersMapObject : Symbol(ReducersMapObject, Decl(reverseMappedTypeInferenceSameSource1.ts, 9, 7)) | ||
| >S : Symbol(S, Decl(reverseMappedTypeInferenceSameSource1.ts, 15, 32)) | ||
| >A : Symbol(A, Decl(reverseMappedTypeInferenceSameSource1.ts, 15, 40)) | ||
| } | ||
|
|
||
| declare function configureStore<S = any, A extends Action = UnknownAction>( | ||
| >configureStore : Symbol(configureStore, Decl(reverseMappedTypeInferenceSameSource1.ts, 17, 1)) | ||
| >S : Symbol(S, Decl(reverseMappedTypeInferenceSameSource1.ts, 19, 32)) | ||
| >A : Symbol(A, Decl(reverseMappedTypeInferenceSameSource1.ts, 19, 40)) | ||
| >Action : Symbol(Action, Decl(reverseMappedTypeInferenceSameSource1.ts, 0, 0)) | ||
| >UnknownAction : Symbol(UnknownAction, Decl(reverseMappedTypeInferenceSameSource1.ts, 2, 2)) | ||
|
|
||
| options: ConfigureStoreOptions<S, A>, | ||
| >options : Symbol(options, Decl(reverseMappedTypeInferenceSameSource1.ts, 19, 75)) | ||
| >ConfigureStoreOptions : Symbol(ConfigureStoreOptions, Decl(reverseMappedTypeInferenceSameSource1.ts, 13, 2)) | ||
| >S : Symbol(S, Decl(reverseMappedTypeInferenceSameSource1.ts, 19, 32)) | ||
| >A : Symbol(A, Decl(reverseMappedTypeInferenceSameSource1.ts, 19, 40)) | ||
|
|
||
| ): void; | ||
|
|
||
| { | ||
| const reducer: Reducer<number> = () => 0; | ||
| >reducer : Symbol(reducer, Decl(reverseMappedTypeInferenceSameSource1.ts, 24, 7)) | ||
| >Reducer : Symbol(Reducer, Decl(reverseMappedTypeInferenceSameSource1.ts, 5, 1)) | ||
|
|
||
| const store1 = configureStore({ reducer }); // comment it out to see the error go away | ||
| >store1 : Symbol(store1, Decl(reverseMappedTypeInferenceSameSource1.ts, 25, 7)) | ||
| >configureStore : Symbol(configureStore, Decl(reverseMappedTypeInferenceSameSource1.ts, 17, 1)) | ||
| >reducer : Symbol(reducer, Decl(reverseMappedTypeInferenceSameSource1.ts, 25, 33)) | ||
| } | ||
|
|
||
| const counterReducer1: Reducer<number> = () => 0; | ||
| >counterReducer1 : Symbol(counterReducer1, Decl(reverseMappedTypeInferenceSameSource1.ts, 28, 5)) | ||
| >Reducer : Symbol(Reducer, Decl(reverseMappedTypeInferenceSameSource1.ts, 5, 1)) | ||
|
|
||
| const store2 = configureStore({ | ||
| >store2 : Symbol(store2, Decl(reverseMappedTypeInferenceSameSource1.ts, 30, 5)) | ||
| >configureStore : Symbol(configureStore, Decl(reverseMappedTypeInferenceSameSource1.ts, 17, 1)) | ||
|
|
||
| reducer: { | ||
| >reducer : Symbol(reducer, Decl(reverseMappedTypeInferenceSameSource1.ts, 30, 31)) | ||
|
|
||
| counter1: counterReducer1, | ||
| >counter1 : Symbol(counter1, Decl(reverseMappedTypeInferenceSameSource1.ts, 31, 12)) | ||
| >counterReducer1 : Symbol(counterReducer1, Decl(reverseMappedTypeInferenceSameSource1.ts, 28, 5)) | ||
|
|
||
| }, | ||
| }); | ||
|
|
||
| export {} |
110 changes: 110 additions & 0 deletions
110
tests/baselines/reference/reverseMappedTypeInferenceSameSource1.types
This file contains hidden or 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,110 @@ | ||
| //// [tests/cases/compiler/reverseMappedTypeInferenceSameSource1.ts] //// | ||
|
|
||
| === reverseMappedTypeInferenceSameSource1.ts === | ||
| type Action<T extends string = string> = { | ||
| >Action : Action<T> | ||
| > : ^^^^^^^^^ | ||
|
|
||
| type: T; | ||
| >type : T | ||
| > : ^ | ||
|
|
||
| }; | ||
| interface UnknownAction extends Action { | ||
| [extraProps: string]: unknown; | ||
| >extraProps : string | ||
| > : ^^^^^^ | ||
| } | ||
| type Reducer<S = any, A extends Action = UnknownAction> = ( | ||
| >Reducer : Reducer<S, A> | ||
| > : ^^^^^^^^^^^^^ | ||
|
|
||
| state: S | undefined, | ||
| >state : S | undefined | ||
| > : ^^^^^^^^^^^^^ | ||
|
|
||
| action: A, | ||
| >action : A | ||
| > : ^ | ||
|
|
||
| ) => S; | ||
|
|
||
| type ReducersMapObject<S = any, A extends Action = UnknownAction> = { | ||
| >ReducersMapObject : ReducersMapObject<S, A> | ||
| > : ^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| [K in keyof S]: Reducer<S[K], A>; | ||
| }; | ||
|
|
||
| interface ConfigureStoreOptions<S = any, A extends Action = UnknownAction> { | ||
| reducer: Reducer<S, A> | ReducersMapObject<S, A>; | ||
| >reducer : Reducer<S, A> | ReducersMapObject<S, A> | ||
| > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| } | ||
|
|
||
| declare function configureStore<S = any, A extends Action = UnknownAction>( | ||
| >configureStore : <S = any, A extends Action<string> = UnknownAction>(options: ConfigureStoreOptions<S, A>) => void | ||
| > : ^ ^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^ | ||
|
|
||
| options: ConfigureStoreOptions<S, A>, | ||
| >options : ConfigureStoreOptions<S, A> | ||
| > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| ): void; | ||
|
|
||
| { | ||
| const reducer: Reducer<number> = () => 0; | ||
| >reducer : Reducer<number, UnknownAction> | ||
| > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| >() => 0 : () => number | ||
| > : ^^^^^^^^^^^^ | ||
| >0 : 0 | ||
| > : ^ | ||
|
|
||
| const store1 = configureStore({ reducer }); // comment it out to see the error go away | ||
| >store1 : void | ||
| > : ^^^^ | ||
| >configureStore({ reducer }) : void | ||
| > : ^^^^ | ||
| >configureStore : <S = any, A extends Action<string> = UnknownAction>(options: ConfigureStoreOptions<S, A>) => void | ||
| > : ^ ^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^ | ||
| >{ reducer } : { reducer: Reducer<number, UnknownAction>; } | ||
| > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| >reducer : Reducer<number, UnknownAction> | ||
| > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| } | ||
|
|
||
| const counterReducer1: Reducer<number> = () => 0; | ||
| >counterReducer1 : Reducer<number, UnknownAction> | ||
| > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| >() => 0 : () => number | ||
| > : ^^^^^^^^^^^^ | ||
| >0 : 0 | ||
| > : ^ | ||
|
|
||
| const store2 = configureStore({ | ||
| >store2 : void | ||
| > : ^^^^ | ||
| >configureStore({ reducer: { counter1: counterReducer1, },}) : void | ||
| > : ^^^^ | ||
| >configureStore : <S = any, A extends Action<string> = UnknownAction>(options: ConfigureStoreOptions<S, A>) => void | ||
| > : ^ ^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^ | ||
| >{ reducer: { counter1: counterReducer1, },} : { reducer: { counter1: Reducer<number, UnknownAction>; }; } | ||
| > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| reducer: { | ||
| >reducer : { counter1: Reducer<number, UnknownAction>; } | ||
| > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| >{ counter1: counterReducer1, } : { counter1: Reducer<number, UnknownAction>; } | ||
| > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| counter1: counterReducer1, | ||
| >counter1 : Reducer<number, UnknownAction> | ||
| > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| >counterReducer1 : Reducer<number, UnknownAction> | ||
| > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| }, | ||
| }); | ||
|
|
||
| export {} |
40 changes: 40 additions & 0 deletions
40
tests/cases/compiler/reverseMappedTypeInferenceSameSource1.ts
This file contains hidden or 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,40 @@ | ||
| // @strict: true | ||
| // @noEmit: true | ||
|
|
||
| type Action<T extends string = string> = { | ||
| type: T; | ||
| }; | ||
| interface UnknownAction extends Action { | ||
| [extraProps: string]: unknown; | ||
| } | ||
| type Reducer<S = any, A extends Action = UnknownAction> = ( | ||
| state: S | undefined, | ||
| action: A, | ||
| ) => S; | ||
|
|
||
| type ReducersMapObject<S = any, A extends Action = UnknownAction> = { | ||
| [K in keyof S]: Reducer<S[K], A>; | ||
| }; | ||
|
|
||
| interface ConfigureStoreOptions<S = any, A extends Action = UnknownAction> { | ||
| reducer: Reducer<S, A> | ReducersMapObject<S, A>; | ||
| } | ||
|
|
||
| declare function configureStore<S = any, A extends Action = UnknownAction>( | ||
| options: ConfigureStoreOptions<S, A>, | ||
| ): void; | ||
|
|
||
| { | ||
| const reducer: Reducer<number> = () => 0; | ||
| const store1 = configureStore({ reducer }); // comment it out to see the error go away | ||
| } | ||
|
|
||
| const counterReducer1: Reducer<number> = () => 0; | ||
|
|
||
| const store2 = configureStore({ | ||
| reducer: { | ||
| counter1: counterReducer1, | ||
| }, | ||
| }); | ||
|
|
||
| export {} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.