-
Notifications
You must be signed in to change notification settings - Fork 6
More type safety for language keys #93
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
base: main
Are you sure you want to change the base?
Conversation
…ctions and operators
…ting definitions even more
…anguageNode`, wrote documentation about validation
Lotes
left a comment
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 like the type specific bundle. It gives the opportunity to carry along language-specific types, similar to the dependency injection, which bundles values of services.
I also like those lookup functions, so that you do not have to break apart the specifics on your own.
Most stuff is a replacement for the old types, but I found one little thing, where I wonder if we can make this better.
| * otherwise the given options are used to register the return validation rule now. | ||
| */ | ||
| registration: 'MYSELF' | Partial<ValidationRuleOptions>; | ||
| registration: 'MYSELF' | Partial<ValidationRuleOptions<Specifics>>; |
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.
This MYSELF feels weird. Is the user not free in using this API? At a different position you are checking if it is MYSELF only in order to skip something. I am wondering if that can be done differently. Looks hacky, but have no better arguments ^^
This PR increases the TypeScript type-safety and can be seen as a follow-up of #90
TypirSpecificsnow contain the propertyLanguageKeys: Record<string, unknown>;to make language keys explicit. This is the precondition for the following improvements:Specifics['LanguageKeys']to simplify inference rules for functions and operators: Now it is possible to skip the TypeScript type when using onlylanguageKeyand nofilter. @Lotes You sketched this idea some time ago and now we have everything to make your idea happen 🙂Contributions of this PR which are not related to language keys:
languagePropertysupports only valid property names of the givenlanguageNodeOpen issues:
Specifics['LanguageKeys']now even in Typir (core), we could support the featuresaddValidationRulesForAstNodesandaddInferenceRulesForAstNodes(which are Typir-Langium only so far) also in Typir (core): I would prefer that (but did not implement that yet), what do you think?typir.ts, there are two open issues/improvements marked with// possible extension, for which I found no solution so farI recommend to review this PR commit by commit.