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

[TS] Allows object API to set 0 for a null-default scalar. #7864

Merged
merged 13 commits into from
Sep 12, 2023
6 changes: 1 addition & 5 deletions src/idl_gen_ts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1983,11 +1983,7 @@ class TsGenerator : public BaseGenerator {
if (!IsScalar(field.value.type.base_type)) {
code += "0";
} else if (HasNullDefault(field)) {
if (IsLong(field.value.type.base_type)) {
code += "BigInt(0)";
} else {
code += "0";
}
code += "null";
} else {
if (field.value.type.base_type == BASE_TYPE_BOOL) { code += "+"; }
code += GenDefaultValue(field, imports);
Expand Down
12 changes: 6 additions & 6 deletions ts/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,42 +202,42 @@ export class Builder {
this.writeFloat64(value);
}

addFieldInt8(voffset: number, value: number, defaultValue: number): void {
addFieldInt8(voffset: number, value: number, defaultValue: number|null): void {
if (this.force_defaults || value != defaultValue) {
this.addInt8(value);
this.slot(voffset);
}
}

addFieldInt16(voffset: number, value: number, defaultValue: number): void {
addFieldInt16(voffset: number, value: number, defaultValue: number|null): void {
if (this.force_defaults || value != defaultValue) {
this.addInt16(value);
this.slot(voffset);
}
}

addFieldInt32(voffset: number, value: number, defaultValue: number): void {
addFieldInt32(voffset: number, value: number, defaultValue: number|null): void {
if (this.force_defaults || value != defaultValue) {
this.addInt32(value);
this.slot(voffset);
}
}

addFieldInt64(voffset: number, value: bigint, defaultValue: bigint): void {
addFieldInt64(voffset: number, value: bigint, defaultValue: bigint|null): void {
if (this.force_defaults || value !== defaultValue) {
this.addInt64(value);
this.slot(voffset);
}
}

addFieldFloat32(voffset: number, value: number, defaultValue: number): void {
addFieldFloat32(voffset: number, value: number, defaultValue: number|null): void {
if (this.force_defaults || value != defaultValue) {
this.addFloat32(value);
this.slot(voffset);
}
}

addFieldFloat64(voffset: number, value: number, defaultValue: number): void {
addFieldFloat64(voffset: number, value: number, defaultValue: number|null): void {
if (this.force_defaults || value != defaultValue) {
this.addFloat64(value);
this.slot(voffset);
Expand Down