Skip to content

Mapped inference types do not work as I understand #21765

Closed
@AlexStacker

Description

@AlexStacker

Directly show my code, the text description may not be clear.
From the callback function used in the parameters

TypeScript Version: 2.6.2

Code

interface MapType { 
    a: {
        w: number;
        h: number;
    }
    b: {
        s: string;
        n: boolean;
    }
    q: {
        s: string;
        n: boolean;
    }
}

type NS<T, P extends keyof T> = {
    [U in keyof T[P]]: T[P][U] 
}

let n: NS<MapType, 'a' | 'b'>
n.s //Property 's' does not exist on type 'NS<M, "a" | "b">'.
let m: NS<MapType, 'a'>
m.h // (property) h: number

Expected behavior:

let n: NS<MapType, 'a' | 'b'>
n.s // string
n.n // boolean
n.w // number
n.h // number

Actual behavior:

let n: NS<MapType, 'a' | 'b'>
n.s //Property 's' does not exist on type 'NS<M, "a" | "b">'.

Playground Link:

Related Issues:
I think this is very helpful to me,But did not solve my problem.
17930

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions