Closed
Description
//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]
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
jcalz commentedon Oct 11, 2017
Duplicate of #15756. This will be fixed in TypeScript 2.6.
[-]keyof T Bug[/-][+][keyof T] Bug[/+]