Skip to content

Commit b38a668

Browse files
Martin Traversemartin-traverse
authored andcommitted
Fixes optional handling for class-level comments (JS) and interfaces (TS)
1 parent 0a0cdb6 commit b38a668

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

cli/targets/static.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,14 @@ function toJsType(field) {
354354
return type;
355355
}
356356

357+
function handleOptionalFields(jsType, field) {
358+
359+
if (field.optional && !field.map && !field.repeated && (field.resolvedType instanceof Type || config["null-defaults"]) || field.partOf)
360+
return jsType + "|null|undefined";
361+
else
362+
return jsType
363+
}
364+
357365
function buildType(ref, type) {
358366

359367
if (config.comments) {
@@ -366,8 +374,7 @@ function buildType(ref, type) {
366374
var prop = util.safeProp(field.name); // either .name or ["name"]
367375
prop = prop.substring(1, prop.charAt(0) === "[" ? prop.length - 1 : prop.length);
368376
var jsType = toJsType(field);
369-
if (field.optional)
370-
jsType = jsType + "|null";
377+
jsType = handleOptionalFields(jsType, field);
371378
typeDef.push("@property {" + jsType + "} " + (field.optional ? "[" + prop + "]" : prop) + " " + (field.comment || type.name + " " + field.name));
372379
});
373380
push("");
@@ -394,8 +401,7 @@ function buildType(ref, type) {
394401
if (config.comments) {
395402
push("");
396403
var jsType = toJsType(field);
397-
if (field.optional && !field.map && !field.repeated && (field.resolvedType instanceof Type || config["null-defaults"]) || field.partOf)
398-
jsType = jsType + "|null|undefined";
404+
jsType = handleOptionalFields(jsType, field);
399405
pushComment([
400406
field.comment || type.name + " " + field.name + ".",
401407
"@member {" + jsType + "} " + field.name,

0 commit comments

Comments
 (0)