From e4fb86651cc063b3e55f77a589aa0825fba2bd2b Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sun, 31 Jan 2021 13:05:16 -0700 Subject: [PATCH] fix: Missing comments on optional methods Resolves #1490 --- src/lib/converter/symbols.ts | 4 +- src/test/converter/comment/comment.ts | 5 +++ src/test/converter/comment/specs.json | 64 ++++++++++++++++++++++++--- 3 files changed, 65 insertions(+), 8 deletions(-) diff --git a/src/lib/converter/symbols.ts b/src/lib/converter/symbols.ts index 86a680096..ca919d533 100644 --- a/src/lib/converter/symbols.ts +++ b/src/lib/converter/symbols.ts @@ -309,7 +309,9 @@ function convertFunctionOrMethod( symbol, locationDeclaration ); - const signatures = type.getCallSignatures(); + // Need to get the non nullable type because interface methods might be declared + // with a question token. See GH1490. + const signatures = type.getNonNullableType().getCallSignatures(); const reflection = context.createDeclarationReflection( context.scope.kindOf( diff --git a/src/test/converter/comment/comment.ts b/src/test/converter/comment/comment.ts index 654bd42a6..650aa3ade 100644 --- a/src/test/converter/comment/comment.ts +++ b/src/test/converter/comment/comment.ts @@ -91,3 +91,8 @@ export class CommentedClass { export function gh1164(scope: string) { return scope; } + +export interface GH1490 { + /** With comment */ + optionalMethod?(): void; +} diff --git a/src/test/converter/comment/specs.json b/src/test/converter/comment/specs.json index 6f178c303..eb45efd51 100644 --- a/src/test/converter/comment/specs.json +++ b/src/test/converter/comment/specs.json @@ -142,6 +142,49 @@ } ] }, + { + "id": 29, + "name": "GH1490", + "kind": 256, + "kindString": "Interface", + "flags": {}, + "children": [ + { + "id": 30, + "name": "optionalMethod", + "kind": 2048, + "kindString": "Method", + "flags": { + "isOptional": true + }, + "signatures": [ + { + "id": 31, + "name": "optionalMethod", + "kind": 4096, + "kindString": "Call signature", + "flags": {}, + "comment": { + "shortText": "With comment" + }, + "type": { + "type": "intrinsic", + "name": "void" + } + } + ] + } + ], + "groups": [ + { + "title": "Methods", + "kind": 2048, + "children": [ + 30 + ] + } + ] + }, { "id": 2, "name": "gh1164", @@ -191,6 +234,13 @@ 5 ] }, + { + "title": "Interfaces", + "kind": 256, + "children": [ + 29 + ] + }, { "title": "Functions", "kind": 64, @@ -201,7 +251,7 @@ ] }, { - "id": 29, + "id": 32, "name": "comment2", "kind": 1, "kindString": "Module", @@ -211,21 +261,21 @@ }, "children": [ { - "id": 30, + "id": 33, "name": "multiply", "kind": 64, "kindString": "Function", "flags": {}, "signatures": [ { - "id": 31, + "id": 34, "name": "multiply", "kind": 4096, "kindString": "Call signature", "flags": {}, "parameters": [ { - "id": 32, + "id": 35, "name": "a", "kind": 32768, "kindString": "Parameter", @@ -236,7 +286,7 @@ } }, { - "id": 33, + "id": 36, "name": "b", "kind": 32768, "kindString": "Parameter", @@ -260,7 +310,7 @@ "title": "Functions", "kind": 64, "children": [ - 30 + 33 ] } ] @@ -272,7 +322,7 @@ "kind": 1, "children": [ 1, - 29 + 32 ] } ]