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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails on string literal union types #42

Closed
arosequist opened this issue May 11, 2016 · 5 comments
Closed

Fails on string literal union types #42

arosequist opened this issue May 11, 2016 · 5 comments

Comments

@arosequist
Copy link

This seems to fail when using a union of string literal types.

interface Test {
    first: 'a'; // works
    second: 'a' | 'b'; // fails
}

The error is:

/usr/lib/node_modules/typescript-json-schema/node_modules/typescript/lib/typescript.js:15712
            return symbol.parent ? getFullyQualifiedName(symbol.parent) + "." + symbolToString(symbol) : symbolToString(symbol);
                         ^

TypeError: Cannot read property 'parent' of null
    at Object.getFullyQualifiedName (/usr/lib/node_modules/typescript-json-schema/node_modules/typescript/lib/typescript.js:15712:26)
    at JsonSchemaGenerator.getTypeDefinition (/usr/lib/node_modules/typescript-json-schema/typescript-json-schema.js:315:35)
    at JsonSchemaGenerator.getDefinitionForProperty (/usr/lib/node_modules/typescript-json-schema/typescript-json-schema.js:154:35)
    at /usr/lib/node_modules/typescript-json-schema/typescript-json-schema.js:258:41
    at Array.reduce (native)
    at JsonSchemaGenerator.getClassDefinition (/usr/lib/node_modules/typescript-json-schema/typescript-json-schema.js:256:49)
    at JsonSchemaGenerator.getTypeDefinition (/usr/lib/node_modules/typescript-json-schema/typescript-json-schema.js:356:26)
    at JsonSchemaGenerator.getDefinitionForRootType (/usr/lib/node_modules/typescript-json-schema/typescript-json-schema.js:131:49)
    at JsonSchemaGenerator.getTypeDefinition (/usr/lib/node_modules/typescript-json-schema/typescript-json-schema.js:350:26)
    at JsonSchemaGenerator.getDefinitionForProperty (/usr/lib/node_modules/typescript-json-schema/typescript-json-schema.js:154:35)
@arosequist
Copy link
Author

I just noticed typescript-json-schema/test/programs/string-literals/main.ts, which seems to cover this scenario. I'll do some more digging to isolate the specific situation.

@arosequist
Copy link
Author

It works if the enum list is separated into its own type, and fails if it's declared inline.

Works:

type result = "ok" | "fail" | "abort";

class MyObject {
    foo: result
}

Fails:

class MyObject {
    foo: "ok" | "fail" | "abort";
}

Unfortunately, I don't know enough about the internals to know how easy of a fix this is.

SupernaviX added a commit to SupernaviX/typescript-json-schema that referenced this issue Jul 5, 2016
YousefED added a commit that referenced this issue Jul 5, 2016
@YousefED
Copy link
Owner

@SupernaviX if this is still an issue and you have fixed it, would you mind submitting a PR with proper tests?

@SupernaviX
Copy link
Contributor

I did, you've already merged it #45

@YousefED
Copy link
Owner

My bad! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants