diff --git a/src/main.ts b/src/main.ts index 265310f89..7de80cb43 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1264,7 +1264,7 @@ function generateBaseInstanceFactory( let val; if (keyValuePair) { - val = '""'; + val = defaultValue(ctx, { ...field, label: FieldDescriptorProto_Label.LABEL_REQUIRED }); } else if (isWithinOneOf(field)) { val = nullOrUndefined(options); } else if (isMapType(ctx, messageDesc, field)) { @@ -2759,7 +2759,7 @@ function generateFromPartial(ctx: Context, fullName: string, messageDesc: Descri let fallback if (keyValuePair) { - fallback = '""' + fallback = defaultValue(ctx, { ...field, label: FieldDescriptorProto_Label.LABEL_REQUIRED }) } else { fallback = isWithinOneOf(field) || noDefaultValue ? "undefined" : defaultValue(ctx, field); } diff --git a/src/types.ts b/src/types.ts index 8d8abb206..0ab684bb3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -479,11 +479,9 @@ export function isKeyValuePair(fields: FieldDescriptorProto[]) { return fields.length === 2 && fields[0].name === "key" && fields[0].number === 1 && - fields[0].type === FieldDescriptorProto_Type.TYPE_STRING && fields[0].label === FieldDescriptorProto_Label.LABEL_OPTIONAL && fields[1].name === "value" && fields[1].number === 2 && - fields[1].type === FieldDescriptorProto_Type.TYPE_STRING && fields[1].label === FieldDescriptorProto_Label.LABEL_OPTIONAL; }