-
Notifications
You must be signed in to change notification settings - Fork 763
Closed
Labels
Domain: Declaration EmitRelated to declaration emit, type printingRelated to declaration emit, type printing
Description
The following code generates incorrect types when using tsgo as the type of the read only property is not narrowed to its constant value.
This has the negative consequences of breaking discriminated unions of class instances that use readonly props as discriminato.
Steps to reproduce
enum Types {
'A' = 'A',
'B' = 'B'
}
export class LiteralA {
readonly type = 'A';
}
export class LiteralB {
readonly type = 'B';
}
export class EnumA {
readonly type = Types.A;
}
export class EnumB {
readonly type = Types. B;
}Behavior with typescript@5.9
declare enum Types {
'A' = "A",
'B' = "B”
}
export declare class LiteralA {
readonly type = "A";
}
export declare class LiteralB {
readonly type = "B";
}
export declare class EnumA {
readonly type = Types['A'];
}
export declare class EnumB {
readonly type = Types['B'];
} Behavior with tsgo
declare enum Types {
'A' = "A",
'B' = "B”
}
export declare class LiteralA {
readonly type = string;
}
export declare class LiteralB {
readonly type = string;
}
export declare class EnumA {
readonly type = Types;
}
export declare class EnumB {
readonly type = Types;
} Metadata
Metadata
Assignees
Labels
Domain: Declaration EmitRelated to declaration emit, type printingRelated to declaration emit, type printing