fix(typescript): Handle invalid type names#317
Merged
fabien0102 merged 2 commits intofabien0102:mainfrom Jan 28, 2026
Merged
Conversation
7ce0868 to
5e6a919
Compare
|
+1 |
fabien0102
requested changes
Sep 8, 2025
Owner
fabien0102
left a comment
There was a problem hiding this comment.
Interesting edge case, let’s try to make it even more fancy for the number only (the function is already there)
Comment on lines
952
to
955
| expect(printSchema(schema, "200")).toMatchInlineSnapshot(` | ||
| "export type _200 = void;" | ||
| `); | ||
| }); |
Owner
There was a problem hiding this comment.
For the case where it’s only numbers, we could use this
57ebc4f to
9d8b639
Compare
9d8b639 to
14e8de3
Compare
sschw
commented
Jan 12, 2026
|
|
||
| // If the identifier is now empty, set it to "_". | ||
| if (identifier.length === 0) { | ||
| identifier = "_"; |
Contributor
Author
There was a problem hiding this comment.
We could name it here "NoValidName" or we use the invalid name here.
I just kept the "_" as placeholder.
sschw
commented
Jan 12, 2026
|
|
||
| let identifier = pascal(name); | ||
|
|
||
| if (identifier.length > 0 && !isNaN(Number(identifier))) { |
Contributor
Author
There was a problem hiding this comment.
This check will also convert "0123" to "OneTwoThree", as it can convert it to a number.
What do you prefer? Either we ignore this, add a handling for "Zero" at the start or we let the check fail and handle this case in the "else"-block
Owner
There was a problem hiding this comment.
Should be fine without the "Zero" handling.
fabien0102
approved these changes
Jan 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I recently saw that there is an issue with certain names in the schema.
The schema above will generate the definition
export type 400 = voidwhere 400 is an invalid identifier.The problem happens in schemaToTypeAliasDeclaration as the name is used without any check for its validity.
I addressed this issue by prepending invalid names by
_and if they are still invalid, by removing any non A-Za-z0-9 characters.It might cause collisions though if you have e.g.
400and_400, or you use a schema full of e.g. emojis as names.