Skip to content

[keyof T] Bug #19095

Closed
Closed
@fc01

Description

@fc01
//Type A ----> Type B
export type A = {
    f1: { x: number, y: number },
    f2: { str: string }
}

export type B =
    { type: 'f1', x: number, y: number } |
    { type: 'f2', str: string }




//error
type GetB<T> = {
    [P in keyof T]: T[P] & { type: P }
}[keyof T]

export type XXX = GetB<A>

/* type XXX is ??

({
    x: number;
    y: number;
} & {
    type: "f1" | "f2";  //<---------------------  ???
}) | ({
    str: string;
} & {
    type: "f1" | "f2";  //<---------------------  ???
})

*/


//right
type GetB2<T> = {
    [P in keyof T]: T[P] & { type: P }
}
export type XXX2 = GetB2<A>[keyof A] 

Activity

jcalz

jcalz commented on Oct 11, 2017

@jcalz
Contributor

Duplicate of #15756. This will be fixed in TypeScript 2.6.

changed the title [-]keyof T Bug[/-] [+][keyof T] Bug[/+] on Oct 11, 2017
locked and limited conversation to collaborators on Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jcalz@mhegazy@fc01

        Issue actions

          [keyof T] Bug · Issue #19095 · microsoft/TypeScript