Skip to content

Commit 34d05f2

Browse files
committed
fix: Support JSDocNullableType, JSDocNonNullableType
Resolves #1524
1 parent c9faa9b commit 34d05f2

File tree

4 files changed

+169
-36
lines changed

4 files changed

+169
-36
lines changed

src/lib/converter/types.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ export function loadConverters() {
8585
tupleConverter,
8686
typeOperatorConverter,
8787
unionConverter,
88+
// Only used if skipLibCheck: true
89+
jsDocNullableTypeConverter,
90+
jsDocNonNullableTypeConverter,
8891
]) {
8992
for (const key of actor.kind) {
9093
if (key === undefined) {
@@ -986,6 +989,27 @@ const unionConverter: TypeConverter<ts.UnionTypeNode, ts.UnionType> = {
986989
},
987990
};
988991

992+
const jsDocNullableTypeConverter: TypeConverter<ts.JSDocNullableType> = {
993+
kind: [ts.SyntaxKind.JSDocNullableType],
994+
convert(context, node) {
995+
return new UnionType([
996+
convertType(context, node.type),
997+
new LiteralType(null),
998+
]);
999+
},
1000+
// Should be a UnionType
1001+
convertType: requestBugReport,
1002+
};
1003+
1004+
const jsDocNonNullableTypeConverter: TypeConverter<ts.JSDocNonNullableType> = {
1005+
kind: [ts.SyntaxKind.JSDocNonNullableType],
1006+
convert(context, node) {
1007+
return convertType(context, node.type);
1008+
},
1009+
// Should be a UnionType
1010+
convertType: requestBugReport,
1011+
};
1012+
9891013
function requestBugReport(context: Context, nodeOrType: ts.Node | ts.Type) {
9901014
if ("kind" in nodeOrType) {
9911015
const kindName = ts.SyntaxKind[nodeOrType.kind];

src/test/converter/declaration/declaration.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@ export declare class Decl {
33
}
44

55
export declare const x: number;
6+
7+
export namespace GH1524 {
8+
export function nullable(opt: ?string): void;
9+
export function nonNullable(opt: !string): void;
10+
}

0 commit comments

Comments
 (0)