Skip to content

Commit

Permalink
Use ?: instead of |undefined in .d.ts files
Browse files Browse the repository at this point in the history
  • Loading branch information
foxdavidj committed Feb 23, 2017
1 parent f8b415a commit 37536e5
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/tsd-jsdoc/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,18 @@ function writeInterface(element) {

// handles a single element of any understood type
function handleElement(element, parent, insideClass) {
if (element.optional !== true && element.type && element.type.names && element.type.names.length) {
for (let i = 0; i < element.type.names.length; i++) {
if (element.type.names[i].toLowerCase() === 'undefined') {
// This element is actually optional. Set optional to true and
// remove the 'undefined' type
element.optional = true;
element.type.names.splice(i, 1);
i--;
}
}
}

if (seen[element.longname])
return true;
if (isClassLike(element)) {
Expand Down Expand Up @@ -460,7 +472,10 @@ function handleMember(element, parent) {
} else
write(element.kind === "constant" ? "const " : "var ");

write(element.name, ": ");
write(element.name);
if (element.optional)
write("?");
write(": ");

if (element.type && element.type.names && /^Object\b/i.test(element.type.names[0]) && element.properties) {
writeln("{");
Expand Down

0 comments on commit 37536e5

Please sign in to comment.