Skip to content

Commit

Permalink
fix: Setters should always have a void return type
Browse files Browse the repository at this point in the history
Closes #1215
  • Loading branch information
Gerrit0 committed Jun 15, 2021
1 parent d9e66b2 commit 1dc5659
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/lib/converter/factories/signature.ts
Expand Up @@ -2,6 +2,7 @@ import * as ts from "typescript";
import * as assert from "assert";
import {
DeclarationReflection,
IntrinsicType,
ParameterReflection,
PredicateType,
Reflection,
Expand Down Expand Up @@ -67,6 +68,8 @@ export function createSignature(
const predicate = context.checker.getTypePredicateOfSignature(signature);
if (predicate) {
sigRef.type = convertPredicate(predicate, context.withScope(sigRef));
} else if (kind == ReflectionKind.SetSignature) {
sigRef.type = new IntrinsicType("void");
} else {
sigRef.type = context.converter.convertType(
context.withScope(sigRef),
Expand Down
7 changes: 7 additions & 0 deletions src/test/converter2.test.ts
Expand Up @@ -7,6 +7,7 @@ import {
DeclarationReflection,
ProjectReflection,
ReflectionKind,
SignatureReflection,
} from "../lib/models";

function query(project: ProjectReflection, name: string) {
Expand Down Expand Up @@ -56,6 +57,12 @@ const issueTests: Record<string, (project: ProjectReflection) => void> = {
equal(refl.signatures?.[0]?.comment?.returns, "Test description.\n");
},

gh1215(project) {
const foo = query(project, "Foo.bar");
ok(foo.setSignature instanceof SignatureReflection);
equal(foo.setSignature.type?.toString(), "void");
},

gh1255(project) {
const foo = query(project, "C.foo");
equal(foo.comment?.shortText, "Docs!");
Expand Down
3 changes: 3 additions & 0 deletions src/test/converter2/issues/gh1215.d.ts
@@ -0,0 +1,3 @@
declare class Foo {
set bar(bar: string);
}

0 comments on commit 1dc5659

Please sign in to comment.