Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: failed to resolve type for typeof static class property #1119

Merged
merged 1 commit into from Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"
}
}
}