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

fix: support non-literal types in template literal strings #1509

Merged
merged 11 commits into from
Dec 22, 2022
Merged

fix: support non-literal types in template literal strings #1509

merged 11 commits into from
Dec 22, 2022

Conversation

flugg
Copy link
Contributor

@flugg flugg commented Dec 20, 2022

When given a template literal type which contains a number type, for instance:

type Foo = `${number}`;

The generator fails with Unknown type "number".

This PR solves this by simply returning a StringType when a template literal string contains a number type, which makes sense, because JSON Schema can't really represent these types easily. I feel like making a regex-converter for these types is a bit overkill.

Copy link
Member

@domoritz domoritz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the pull request.

src/NodeParser/StringTemplateLiteralNodeParser.ts Outdated Show resolved Hide resolved
@domoritz domoritz changed the title Support number types in template literal strings fix: support number types in template literal strings Dec 21, 2022
@flugg flugg changed the title fix: support number types in template literal strings fix: support non-literal types in template literal strings Dec 21, 2022
@flugg
Copy link
Contributor Author

flugg commented Dec 21, 2022

This change seemed to affect how template literal strings worked in mapped types and broke another test. I changed it to check for LiteralType, UnionType and AliasType, which is what the extractLiterals function checks below. Looks like this solved everything and allows for other non-literal types than just numbers.

@domoritz domoritz merged commit 0ac5df1 into vega:next Dec 22, 2022
@domoritz
Copy link
Member

Thank you!

@github-actions github-actions bot mentioned this pull request Dec 22, 2022
@github-actions
Copy link

🚀 PR was released in v1.2.0 🚀

@github-actions github-actions bot added released This issue/pull request has been released. and removed prerelease labels Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released This issue/pull request has been released.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants