Skip to content

Commit

Permalink
fix: Support JSDocNullableType, JSDocNonNullableType
Browse files Browse the repository at this point in the history
Resolves #1524
  • Loading branch information
Gerrit0 committed Mar 6, 2021
1 parent c9faa9b commit 34d05f2
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 36 deletions.
24 changes: 24 additions & 0 deletions src/lib/converter/types.ts
Expand Up @@ -85,6 +85,9 @@ export function loadConverters() {
tupleConverter,
typeOperatorConverter,
unionConverter,
// Only used if skipLibCheck: true
jsDocNullableTypeConverter,
jsDocNonNullableTypeConverter,
]) {
for (const key of actor.kind) {
if (key === undefined) {
Expand Down Expand Up @@ -986,6 +989,27 @@ const unionConverter: TypeConverter<ts.UnionTypeNode, ts.UnionType> = {
},
};

const jsDocNullableTypeConverter: TypeConverter<ts.JSDocNullableType> = {
kind: [ts.SyntaxKind.JSDocNullableType],
convert(context, node) {
return new UnionType([
convertType(context, node.type),
new LiteralType(null),
]);
},
// Should be a UnionType
convertType: requestBugReport,
};

const jsDocNonNullableTypeConverter: TypeConverter<ts.JSDocNonNullableType> = {
kind: [ts.SyntaxKind.JSDocNonNullableType],
convert(context, node) {
return convertType(context, node.type);
},
// Should be a UnionType
convertType: requestBugReport,
};

function requestBugReport(context: Context, nodeOrType: ts.Node | ts.Type) {
if ("kind" in nodeOrType) {
const kindName = ts.SyntaxKind[nodeOrType.kind];
Expand Down
5 changes: 5 additions & 0 deletions src/test/converter/declaration/declaration.d.ts
Expand Up @@ -3,3 +3,8 @@ export declare class Decl {
}

export declare const x: number;

export namespace GH1524 {
export function nullable(opt: ?string): void;
export function nonNullable(opt: !string): void;
}

0 comments on commit 34d05f2

Please sign in to comment.