Skip to content

Commit c9faa9b

Browse files
committed
fix: Remove undefined from optional property types
Resolves #1525
1 parent 6fb01a0 commit c9faa9b

File tree

3 files changed

+13
-44
lines changed

3 files changed

+13
-44
lines changed

src/lib/converter/symbols.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { ConverterEvents } from "./converter-events";
2121
import { convertIndexSignature } from "./factories/index-signature";
2222
import { createSignature } from "./factories/signature";
2323
import { convertJsDocAlias, convertJsDocCallback } from "./jsdoc";
24+
import { removeUndefined } from "./utils/reflections";
2425

2526
const symbolConverters: {
2627
[K in ts.SymbolFlags]?: (
@@ -601,6 +602,10 @@ function convertProperty(
601602
(context.isConvertingTypeNode() ? parameterType : void 0) ??
602603
context.checker.getTypeOfSymbolAtLocation(symbol, {} as any)
603604
);
605+
606+
if (reflection.flags.isOptional) {
607+
reflection.type = removeUndefined(reflection.type);
608+
}
604609
}
605610

606611
function convertArrowAsMethod(

src/test/converter/class/specs-with-lump-categories.json

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -358,17 +358,8 @@
358358
"isOptional": true
359359
},
360360
"type": {
361-
"type": "union",
362-
"types": [
363-
{
364-
"type": "intrinsic",
365-
"name": "undefined"
366-
},
367-
{
368-
"type": "intrinsic",
369-
"name": "number"
370-
}
371-
]
361+
"type": "intrinsic",
362+
"name": "number"
372363
}
373364
}
374365
],
@@ -412,17 +403,8 @@
412403
"isReadonly": true
413404
},
414405
"type": {
415-
"type": "union",
416-
"types": [
417-
{
418-
"type": "intrinsic",
419-
"name": "undefined"
420-
},
421-
{
422-
"type": "intrinsic",
423-
"name": "number"
424-
}
425-
]
406+
"type": "intrinsic",
407+
"name": "number"
426408
}
427409
}
428410
],

src/test/converter/class/specs.json

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -358,17 +358,8 @@
358358
"isOptional": true
359359
},
360360
"type": {
361-
"type": "union",
362-
"types": [
363-
{
364-
"type": "intrinsic",
365-
"name": "undefined"
366-
},
367-
{
368-
"type": "intrinsic",
369-
"name": "number"
370-
}
371-
]
361+
"type": "intrinsic",
362+
"name": "number"
372363
}
373364
}
374365
],
@@ -412,17 +403,8 @@
412403
"isReadonly": true
413404
},
414405
"type": {
415-
"type": "union",
416-
"types": [
417-
{
418-
"type": "intrinsic",
419-
"name": "undefined"
420-
},
421-
{
422-
"type": "intrinsic",
423-
"name": "number"
424-
}
425-
]
406+
"type": "intrinsic",
407+
"name": "number"
426408
}
427409
}
428410
],

0 commit comments

Comments
 (0)