Bug Report Checklist
Description
In OpenAPI Generator 7.13.0, the typescript-angular generator changed enum generation to use the as const pattern:
export const MyEnum = {
ValueA: 'ValueA',
ValueB: 'ValueB'
} as const;
export type MyEnum = typeof MyEnum[keyof typeof MyEnum];
While this improves TypeScript typing, it breaks some Angular use cases involving generics, such as:
type MyFormGroup = {
myControl: FormControl<MyEnum>;
}
export class MyClass {
myformGroup: FormGroup<MyFormGroup> = new FormGroup({
myControl: new FormControl(MyEnum.ValueA),
});
}
And produces the following error:
TS2322: Type 'FormGroup<{ myControl: FormControl<"ValueA">; }>' is not assignable to type 'FormGroup<MyFormGroup>'.
Type 'FormControl<MyEnum>' is not assignable to type 'FormControl<"ValueA">'.
Type 'MyEnum' is not assignable to type '"ValueA"'.
Type '"ValueB"' is not assignable to type '"ValueA"'.
EDIT: I have updated the example above with a more relevant one. Before I tried to keep it small, but that specific snippet didn't actually trigger the error.
because MyEnum.ValueA is inferred as a string literal instead of the union type, causing TypeScript errors or forcing unsafe casts. This could be seen as a regression from the previous enum output style in certain cases.
openapi-generator version
v7.13.0
Generation Details
{
"openAPIUrl": "...../swagger.json",
"options": {"ngVersion": "15.1.2"},
}
Steps to reproduce
The above example will trigger a type error.
Related issues/PRs
This change was introduced in #20958, which updated enum generation to use the as const pattern for better typing.
Suggest a fix
Consider adding an optional config flag (e.g., useOldEnumStyle=true) to allow reverting to the previous enum format for compatibility.
Bug Report Checklist
Description
In OpenAPI Generator 7.13.0, the
typescript-angulargenerator changed enum generation to use theas constpattern:While this improves TypeScript typing, it breaks some Angular use cases involving generics, such as:
And produces the following error:
EDIT: I have updated the example above with a more relevant one. Before I tried to keep it small, but that specific snippet didn't actually trigger the error.
because MyEnum.ValueA is inferred as a string literal instead of the union type, causing TypeScript errors or forcing unsafe casts. This could be seen as a regression from the previous enum output style in certain cases.
openapi-generator version
v7.13.0
Generation Details
Steps to reproduce
The above example will trigger a type error.
Related issues/PRs
This change was introduced in #20958, which updated enum generation to use the as const pattern for better typing.
Suggest a fix
Consider adding an optional config flag (e.g., useOldEnumStyle=true) to allow reverting to the previous enum format for compatibility.