-
Notifications
You must be signed in to change notification settings - Fork 69
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
Improve type-safety of the TokenBuilder's options #1586
Improve type-safety of the TokenBuilder's options #1586
Conversation
It now optionally accepts a generic parameter that is a type union of the names of the available terminals of the given language. It should generally be `keyof typeof MyLanguageTerminals` imported from './generated/ast.js'
Hmm, I see that new IndentationAwareTokenBuilder({
indentTokenName: 'INDENT',
dedentTokenName: '' // <-- Here it will suggest only "INDENT"
// (though it wouldn't mark other inputs as erroneous)
}) |
Feel free to update to TypeScript 5.4 as part of this PR. Aside from that the change looks great, thank you! |
Great, done. I'd like to note that I attempted updating to the latest version (5.5), but it gave the following errors (since it now does some RegExp validation), so I thought I'd use 5.4 instead for now and this issue can be addressed separately:
|
I'd also like to add that it could be useful to expose the alias export type ${config.projectName}TerminalNames = keyof typeof ${config.projectName}Terminals; to |
I think that reasonable, yes. Since this is only a type definition, it doesn't even affect bundle size :) |
Hmm, I did not expect the side-effect this had on the tests. Any suggestions for how to best fix it? |
@msujew I'm not sure if you would count that as a fix or a hack, but I noticed that all terminal rules use the name "A" so I just added it to the prefix and it worked 😃 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the tests a bit. This now looks good to me, thank you!
It now optionally accepts a generic parameter that is a type union of the names of the available terminals of the given language. It should generally be
keyof typeof MyLanguageTerminals
imported from'./generated/ast.js'
.Usage:
If the generic parameter is not passed, if falls back to the previous behaviour of simply using strings.