Skip to content

Commit

Permalink
fix: Remove undefined from optional property types
Browse files Browse the repository at this point in the history
Resolves #1525
  • Loading branch information
Gerrit0 committed Mar 5, 2021
1 parent 6fb01a0 commit c9faa9b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 44 deletions.
5 changes: 5 additions & 0 deletions src/lib/converter/symbols.ts
Expand Up @@ -21,6 +21,7 @@ import { ConverterEvents } from "./converter-events";
import { convertIndexSignature } from "./factories/index-signature";
import { createSignature } from "./factories/signature";
import { convertJsDocAlias, convertJsDocCallback } from "./jsdoc";
import { removeUndefined } from "./utils/reflections";

const symbolConverters: {
[K in ts.SymbolFlags]?: (
Expand Down Expand Up @@ -601,6 +602,10 @@ function convertProperty(
(context.isConvertingTypeNode() ? parameterType : void 0) ??
context.checker.getTypeOfSymbolAtLocation(symbol, {} as any)
);

if (reflection.flags.isOptional) {
reflection.type = removeUndefined(reflection.type);
}
}

function convertArrowAsMethod(
Expand Down
26 changes: 4 additions & 22 deletions src/test/converter/class/specs-with-lump-categories.json
Expand Up @@ -358,17 +358,8 @@
"isOptional": true
},
"type": {
"type": "union",
"types": [
{
"type": "intrinsic",
"name": "undefined"
},
{
"type": "intrinsic",
"name": "number"
}
]
"type": "intrinsic",
"name": "number"
}
}
],
Expand Down Expand Up @@ -412,17 +403,8 @@
"isReadonly": true
},
"type": {
"type": "union",
"types": [
{
"type": "intrinsic",
"name": "undefined"
},
{
"type": "intrinsic",
"name": "number"
}
]
"type": "intrinsic",
"name": "number"
}
}
],
Expand Down
26 changes: 4 additions & 22 deletions src/test/converter/class/specs.json
Expand Up @@ -358,17 +358,8 @@
"isOptional": true
},
"type": {
"type": "union",
"types": [
{
"type": "intrinsic",
"name": "undefined"
},
{
"type": "intrinsic",
"name": "number"
}
]
"type": "intrinsic",
"name": "number"
}
}
],
Expand Down Expand Up @@ -412,17 +403,8 @@
"isReadonly": true
},
"type": {
"type": "union",
"types": [
{
"type": "intrinsic",
"name": "undefined"
},
{
"type": "intrinsic",
"name": "number"
}
]
"type": "intrinsic",
"name": "number"
}
}
],
Expand Down

0 comments on commit c9faa9b

Please sign in to comment.