Skip to content

Commit 35898fa

Browse files
committed
Fix: Add '| 0' type union for flags enums without zero value member
1 parent 48a8324 commit 35898fa

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

projects/angular-odata/schematics/apigen/angular/entity.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export class EntityProperty {
2828
if (enumType !== undefined) {
2929
type = enumType.importedName(imports)!;
3030
type += this.edmType.Collection ? '[]' : '';
31+
if (!this.edmType.Collection && enumType.isFlags() && !enumType.hasValue(0)) {
32+
type += ' | 0';
33+
}
3134
} else if (entityType !== undefined) {
3235
type = entityType.importedName(imports)!;
3336
type += this.edmType.Collection ? '[]' : '';

projects/angular-odata/schematics/apigen/angular/enum.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ export class Enum extends Base {
4747
public members() {
4848
return this.edmType.Member.map((m) => `${m.Name} = ${m.Value}`);
4949
}
50-
public flags() {
50+
public isFlags() {
5151
return this.edmType.IsFlags;
5252
}
53+
public hasValue(value: number) {
54+
return this.edmType.Member.some(m => m.Value === value);
55+
}
5356
public override importTypes(): string[] {
5457
return [];
5558
}

projects/angular-odata/schematics/apigen/angular/model.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ export class ModelField {
3030
if (enumType !== undefined) {
3131
type = enumType.importedName(imports)!;
3232
type += this.edmType.Collection ? '[]' : '';
33+
if (!this.edmType.Collection && enumType.isFlags() && !enumType.hasValue(0)) {
34+
type += ' | 0';
35+
}
3336
} else if (entityType !== undefined) {
3437
if (this.edmType.Collection) {
3538
const collection = pkg.findCollection(this.edmType.Type);

0 commit comments

Comments
 (0)