Skip to content

Repeated mapped type inference causes incorrect typeToString results #23897

Open
@RyanCavanaugh

Description

@RyanCavanaugh

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Type DisplayBugs relating to showing types in Quick Info/Tooltips, Signature Help, or Completion Info

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions