Repeated mapped type inference causes incorrect typeToString results
See original GitHub issueTypeScript Version: 2.8.0-insiders.20180320
Search Terms: mapped type inference display typetostring
Code
Via https://stackoverflow.com/questions/50181650/type-inference-lost-inner-level-types-in-typescript
interface IAction {
type: string;
}
type Reducer<S> = (state: S, action: IAction) => S
function combineReducers<S>(reducers: { [K in keyof S]: Reducer<S[K]> }): Reducer<S> {
const dummy = {} as S;
return () => dummy;
}
const test_inner = (test: string, action: IAction) => {
return 'dummy';
}
const test = combineReducers({
test_inner
});
const test_outer = combineReducers({
test
});
// '{test: { test_inner: any } }'
type FinalType = ReturnType<typeof test_outer>;
var k: FinalType;
k.test.test_inner // 'string'
Expected behavior: FinalType
’s hover type should be { test: { test_inner: string } }
Actual behavior: Shows as { test: { test_inner: any } }
Playground Link: Link
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Type inference for constant object provided as function ...
I came around a weird TypeScript behavior and was wondering how to get around it. I have the following function, which accepts a...
Read more >Federated Query Functions in Google Standard SQL | BigQuery
Executes a query on an external database and returns the results as a temporary table. The external database data type is converted to...
Read more >Documentation - Mapped Types - TypeScript
Mapped Types. When you don't want to repeat yourself, sometimes a type needs to be based on another type. Mapped types build on...
Read more >Experimental Design and Analysis - CMU Statistics
CLASSIFICATION BY STATISTICAL TYPE. 15 and number of incorrect turns a rat makes in a maze. For none of these does an answer...
Read more >TypeScript Fundamentals - Joy of Code
Code completion already makes it hard to make such a mistake writing regular JavaScript because ... TypeScript can infer types to provide type...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Oooo GitHub not picking up on the word “doesn’t” before “fix”. 🌞
@weswigham Sure you don’t want to leave this open? As it seems like the issue still exists after the PR.