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
Add a proper non-inferrable type #30856
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//// [genericFunctionInference2.ts] | ||
// Repro from #30685 | ||
|
||
type Reducer<S> = (state: S) => S; | ||
declare function combineReducers<S>(reducers: { [K in keyof S]: Reducer<S[K]> }): Reducer<S>; | ||
|
||
type MyState = { combined: { foo: number } }; | ||
declare const foo: Reducer<MyState['combined']['foo']>; | ||
|
||
const myReducer1: Reducer<MyState> = combineReducers({ | ||
combined: combineReducers({ foo }), | ||
}); | ||
|
||
const myReducer2 = combineReducers({ | ||
combined: combineReducers({ foo }), | ||
}); | ||
|
||
|
||
//// [genericFunctionInference2.js] | ||
// Repro from #30685 | ||
var myReducer1 = combineReducers({ | ||
combined: combineReducers({ foo: foo }) | ||
}); | ||
var myReducer2 = combineReducers({ | ||
combined: combineReducers({ foo: foo }) | ||
}); |
56 changes: 56 additions & 0 deletions
56
tests/baselines/reference/genericFunctionInference2.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,56 @@ | ||
=== tests/cases/compiler/genericFunctionInference2.ts === | ||
// Repro from #30685 | ||
|
||
type Reducer<S> = (state: S) => S; | ||
>Reducer : Symbol(Reducer, Decl(genericFunctionInference2.ts, 0, 0)) | ||
>S : Symbol(S, Decl(genericFunctionInference2.ts, 2, 13)) | ||
>state : Symbol(state, Decl(genericFunctionInference2.ts, 2, 19)) | ||
>S : Symbol(S, Decl(genericFunctionInference2.ts, 2, 13)) | ||
>S : Symbol(S, Decl(genericFunctionInference2.ts, 2, 13)) | ||
|
||
declare function combineReducers<S>(reducers: { [K in keyof S]: Reducer<S[K]> }): Reducer<S>; | ||
>combineReducers : Symbol(combineReducers, Decl(genericFunctionInference2.ts, 2, 34)) | ||
>S : Symbol(S, Decl(genericFunctionInference2.ts, 3, 33)) | ||
>reducers : Symbol(reducers, Decl(genericFunctionInference2.ts, 3, 36)) | ||
>K : Symbol(K, Decl(genericFunctionInference2.ts, 3, 49)) | ||
>S : Symbol(S, Decl(genericFunctionInference2.ts, 3, 33)) | ||
>Reducer : Symbol(Reducer, Decl(genericFunctionInference2.ts, 0, 0)) | ||
>S : Symbol(S, Decl(genericFunctionInference2.ts, 3, 33)) | ||
>K : Symbol(K, Decl(genericFunctionInference2.ts, 3, 49)) | ||
>Reducer : Symbol(Reducer, Decl(genericFunctionInference2.ts, 0, 0)) | ||
>S : Symbol(S, Decl(genericFunctionInference2.ts, 3, 33)) | ||
|
||
type MyState = { combined: { foo: number } }; | ||
>MyState : Symbol(MyState, Decl(genericFunctionInference2.ts, 3, 93)) | ||
>combined : Symbol(combined, Decl(genericFunctionInference2.ts, 5, 16)) | ||
>foo : Symbol(foo, Decl(genericFunctionInference2.ts, 5, 28)) | ||
|
||
declare const foo: Reducer<MyState['combined']['foo']>; | ||
>foo : Symbol(foo, Decl(genericFunctionInference2.ts, 6, 13)) | ||
>Reducer : Symbol(Reducer, Decl(genericFunctionInference2.ts, 0, 0)) | ||
>MyState : Symbol(MyState, Decl(genericFunctionInference2.ts, 3, 93)) | ||
|
||
const myReducer1: Reducer<MyState> = combineReducers({ | ||
>myReducer1 : Symbol(myReducer1, Decl(genericFunctionInference2.ts, 8, 5)) | ||
>Reducer : Symbol(Reducer, Decl(genericFunctionInference2.ts, 0, 0)) | ||
>MyState : Symbol(MyState, Decl(genericFunctionInference2.ts, 3, 93)) | ||
>combineReducers : Symbol(combineReducers, Decl(genericFunctionInference2.ts, 2, 34)) | ||
|
||
combined: combineReducers({ foo }), | ||
>combined : Symbol(combined, Decl(genericFunctionInference2.ts, 8, 54)) | ||
>combineReducers : Symbol(combineReducers, Decl(genericFunctionInference2.ts, 2, 34)) | ||
>foo : Symbol(foo, Decl(genericFunctionInference2.ts, 9, 31)) | ||
|
||
}); | ||
|
||
const myReducer2 = combineReducers({ | ||
>myReducer2 : Symbol(myReducer2, Decl(genericFunctionInference2.ts, 12, 5)) | ||
>combineReducers : Symbol(combineReducers, Decl(genericFunctionInference2.ts, 2, 34)) | ||
|
||
combined: combineReducers({ foo }), | ||
>combined : Symbol(combined, Decl(genericFunctionInference2.ts, 12, 36)) | ||
>combineReducers : Symbol(combineReducers, Decl(genericFunctionInference2.ts, 2, 34)) | ||
>foo : Symbol(foo, Decl(genericFunctionInference2.ts, 13, 31)) | ||
|
||
}); | ||
|
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,49 @@ | ||
=== tests/cases/compiler/genericFunctionInference2.ts === | ||
// Repro from #30685 | ||
|
||
type Reducer<S> = (state: S) => S; | ||
>Reducer : Reducer<S> | ||
>state : S | ||
|
||
declare function combineReducers<S>(reducers: { [K in keyof S]: Reducer<S[K]> }): Reducer<S>; | ||
>combineReducers : <S>(reducers: { [K in keyof S]: Reducer<S[K]>; }) => Reducer<S> | ||
>reducers : { [K in keyof S]: Reducer<S[K]>; } | ||
|
||
type MyState = { combined: { foo: number } }; | ||
>MyState : MyState | ||
>combined : { foo: number; } | ||
>foo : number | ||
|
||
declare const foo: Reducer<MyState['combined']['foo']>; | ||
>foo : Reducer<number> | ||
|
||
const myReducer1: Reducer<MyState> = combineReducers({ | ||
>myReducer1 : Reducer<MyState> | ||
>combineReducers({ combined: combineReducers({ foo }),}) : Reducer<{ combined: { foo: any; }; }> | ||
>combineReducers : <S>(reducers: { [K in keyof S]: Reducer<S[K]>; }) => Reducer<S> | ||
>{ combined: combineReducers({ foo }),} : { combined: Reducer<{ foo: number; }>; } | ||
|
||
combined: combineReducers({ foo }), | ||
>combined : Reducer<{ foo: number; }> | ||
>combineReducers({ foo }) : Reducer<{ foo: number; }> | ||
>combineReducers : <S>(reducers: { [K in keyof S]: Reducer<S[K]>; }) => Reducer<S> | ||
>{ foo } : { foo: Reducer<number>; } | ||
>foo : Reducer<number> | ||
|
||
}); | ||
|
||
const myReducer2 = combineReducers({ | ||
>myReducer2 : Reducer<{ combined: { foo: any; }; }> | ||
>combineReducers({ combined: combineReducers({ foo }),}) : Reducer<{ combined: { foo: any; }; }> | ||
>combineReducers : <S>(reducers: { [K in keyof S]: Reducer<S[K]>; }) => Reducer<S> | ||
>{ combined: combineReducers({ foo }),} : { combined: Reducer<{ foo: number; }>; } | ||
|
||
combined: combineReducers({ foo }), | ||
>combined : Reducer<{ foo: number; }> | ||
>combineReducers({ foo }) : Reducer<{ foo: number; }> | ||
>combineReducers : <S>(reducers: { [K in keyof S]: Reducer<S[K]>; }) => Reducer<S> | ||
>{ foo } : { foo: Reducer<number>; } | ||
>foo : Reducer<number> | ||
|
||
}); | ||
|
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 @@ | ||
// Repro from #30685 | ||
|
||
type Reducer<S> = (state: S) => S; | ||
declare function combineReducers<S>(reducers: { [K in keyof S]: Reducer<S[K]> }): Reducer<S>; | ||
|
||
type MyState = { combined: { foo: number } }; | ||
declare const foo: Reducer<MyState['combined']['foo']>; | ||
|
||
const myReducer1: Reducer<MyState> = combineReducers({ | ||
combined: combineReducers({ foo }), | ||
}); | ||
|
||
const myReducer2 = combineReducers({ | ||
combined: combineReducers({ foo }), | ||
}); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this supposed to be
Reducer<{ combined: { foo: number; }; }>
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's supposed to be
Reducer<{ combined: { foo: Reducer<number> } }>
, but we never elaborate more than one level of reverse mapped types, thus the any.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhhhhh, right. I thought we printed those with
...
now, rather thanany
, but that may only be for quickinfo...