question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Repeated mapped type inference causes incorrect typeToString results

See original GitHub issue

TypeScript 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:open
  • Created 5 years ago
  • Reactions:5
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
weswighamcommented, Nov 13, 2018

Oooo GitHub not picking up on the word “doesn’t” before “fix”. 🌞

0reactions
Jomikcommented, Nov 13, 2018

@weswigham Sure you don’t want to leave this open? As it seems like the issue still exists after the PR.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found