Skip to content

Commit

Permalink
fix: typescript errors for struct with optional=all
Browse files Browse the repository at this point in the history
  • Loading branch information
UnderKoen committed Feb 26, 2024
1 parent ba97f98 commit 863a7e0
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/generate-struct-wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ export function generateWrapDeep(ctx: Context, fullProtoTypeName: string, fieldN
chunks.push(code`wrap(object: {[key: string]: any} | undefined): Struct {
const struct = createBaseStruct();
if (object !== undefined) {
Object.keys(object).forEach(key => {
${setStatement}
});
if (struct.fields !== undefined) {
for (const key of Object.keys(object)) {
${setStatement}
}
}
}
return struct;
}`);
Expand Down Expand Up @@ -99,18 +101,20 @@ export function generateUnwrapDeep(ctx: Context, fullProtoTypeName: string, fiel
if (ctx.options.useMapType) {
chunks.push(code`unwrap(message: Struct): {[key: string]: any} {
const object: { [key: string]: any } = {};
[...message.fields.keys()].forEach((key) => {
object[key] = Value.unwrap(message.fields.get(key));
});
if (message.fields) {
for (const key of message.fields.keys()) {
object[key] = Value.unwrap(message.fields.get(key));
}
}
return object;
}`);
} else {
chunks.push(code`unwrap(message: Struct): {[key: string]: any} {
const object: { [key: string]: any } = {};
if (message.fields) {
Object.keys(message.fields).forEach(key => {
for (const key of Object.keys(message.fields)) {
object[key] = Value.unwrap(message.fields[key]);
});
}
}
return object;
}`);
Expand Down

0 comments on commit 863a7e0

Please sign in to comment.