From 419eca6f9bec361d2c796872140fc8f2982a5de0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Sat, 5 Oct 2024 15:05:39 -0500 Subject: [PATCH] Do not assume string key and value --- src/main.ts | 4 ++-- src/types.ts | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) 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; }