From 678f463c8b60ddcf4ea2584401b90d21fa4d6e81 Mon Sep 17 00:00:00 2001 From: Fedor Indutnyy Date: Wed, 29 Nov 2023 14:47:33 -0800 Subject: [PATCH] Fix types of sub-messages in class declaration Prior to this change the class' jsdoc comments would state the type of the class properties that encode sub-messages as: /** * Sent editMessage. * @member {proto.IEditMessage|null|undefined} editMessage * @memberof proto.SyncMessage.Sent * @instance */ After the change: /** * Sent editMessage. * @member {proto.EditMessage|null|undefined} editMessage * @memberof proto.SyncMessage.Sent * @instance */ The difference is that the latter specifices the class type and not the interface which better reflects the actual type returned by `.decode()` method. This is a breaking change because constructing the class would now require providing the class instances and not interfaces --- cli/targets/static.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cli/targets/static.js b/cli/targets/static.js index c130d9026..26b0e1f06 100644 --- a/cli/targets/static.js +++ b/cli/targets/static.js @@ -311,9 +311,13 @@ function buildFunction(type, functionName, gen, scope) { push("};"); } -function toJsType(field) { +function toJsType(field, asInterface) { var type; + if (asInterface === undefined) { + asInterface = true; + } + switch (field.type) { case "double": case "float": @@ -342,7 +346,7 @@ function toJsType(field) { break; default: if (field.resolve().resolvedType) - type = exportName(field.resolvedType, !(field.resolvedType instanceof protobuf.Enum || config.forceMessage)); + type = exportName(field.resolvedType, asInterface && !(field.resolvedType instanceof protobuf.Enum || config.forceMessage)); else type = "*"; // should not happen break; @@ -393,7 +397,7 @@ function buildType(ref, type) { var prop = util.safeProp(field.name); if (config.comments) { push(""); - var jsType = toJsType(field); + var jsType = toJsType(field, false); if (field.optional && !field.map && !field.repeated && (field.resolvedType instanceof Type || config["null-defaults"]) || field.partOf) jsType = jsType + "|null|undefined"; pushComment([