Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[keyof T] Bug #19095

Closed
fc01 opened this issue Oct 11, 2017 · 1 comment
Closed

[keyof T] Bug #19095

fc01 opened this issue Oct 11, 2017 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@fc01
Copy link

fc01 commented Oct 11, 2017

//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] 
@jcalz
Copy link
Contributor

jcalz commented Oct 11, 2017

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

@fc01 fc01 closed this as completed Oct 11, 2017
@fc01 fc01 changed the title keyof T Bug [keyof T] Bug Oct 11, 2017
@mhegazy mhegazy added the Duplicate An existing issue was already created label Oct 11, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants