Skip to content

Commit

Permalink
fix: failed to resolve type for typeof static class property (#1119)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkSheinkman committed Feb 8, 2022
1 parent 7fd7b36 commit dd13747
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/NodeParser/TypeofNodeParser.ts
Expand Up @@ -24,7 +24,11 @@ export class TypeofNodeParser implements SubNodeParser {
const valueDec = symbol.valueDeclaration!;
if (ts.isEnumDeclaration(valueDec)) {
return this.createObjectFromEnum(valueDec, context, reference);
} else if (ts.isVariableDeclaration(valueDec) || ts.isPropertySignature(valueDec)) {
} else if (
ts.isVariableDeclaration(valueDec) ||
ts.isPropertySignature(valueDec) ||
ts.isPropertyDeclaration(valueDec)
) {
if (valueDec.type) {
return this.childNodeParser.createType(valueDec.type, context);
} else if (valueDec.initializer) {
Expand Down
1 change: 1 addition & 0 deletions test/valid-data-type.test.ts
Expand Up @@ -59,6 +59,7 @@ describe("valid-data-type", () => {
it("type-typeof", assertValidSchema("type-typeof", "MyType"));
it("type-typeof-value", assertValidSchema("type-typeof-value", "MyType"));
it("type-typeof-object-property", assertValidSchema("type-typeof-object-property", "MyType"));
it("type-typeof-class-static-property", assertValidSchema("type-typeof-class-static-property", "MyType"));
it("type-typeof-enum", assertValidSchema("type-typeof-enum", "MyObject"));
it("type-typeof-class", assertValidSchema("type-typeof-class", "MyObject"));
it("type-keys", assertValidSchema("type-typeof-keys", "MyType"));
Expand Down
5 changes: 5 additions & 0 deletions test/valid-data/type-typeof-class-static-property/main.ts
@@ -0,0 +1,5 @@
class Foo {
static bar = "foo"
}

export type MyType = typeof Foo.bar;
10 changes: 10 additions & 0 deletions test/valid-data/type-typeof-class-static-property/schema.json
@@ -0,0 +1,10 @@
{
"$ref": "#/definitions/MyType",
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"MyType": {
"const": "foo",
"type": "string"
}
}
}

0 comments on commit dd13747

Please sign in to comment.