Skip to content

Conversation

@JohannesMeierSE
Copy link
Collaborator

@JohannesMeierSE JohannesMeierSE commented Sep 4, 2025

This PR increases the TypeScript type-safety and can be seen as a follow-up of #90

  • The TypirSpecifics now contain the property LanguageKeys: Record<string, unknown>; to make language keys explicit. This is the precondition for the following improvements:
  • make properties which are using language keys type-safe
  • exploit Specifics['LanguageKeys'] to simplify inference rules for functions and operators: Now it is possible to skip the TypeScript type when using only languageKey and no filter. @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:

  • languageProperty supports only valid property names of the given languageNode
  • wrote some more documentation

Open issues:

  • Since we have Specifics['LanguageKeys'] now even in Typir (core), we could support the features addValidationRulesForAstNodes and addInferenceRulesForAstNodes (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?
  • In typir.ts, there are two open issues/improvements marked with // possible extension, for which I found no solution so far

I recommend to review this PR commit by commit.

@JohannesMeierSE JohannesMeierSE added this to the v0.4 milestone Sep 4, 2025
Copy link
Collaborator

@Lotes Lotes left a 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>>;
Copy link
Collaborator

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 ^^

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

Successfully merging this pull request may close these issues.

3 participants