question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve type inferrence of data type rules

See original GitHub issue

The idea came from the discussion. Currently, ON returns string: 'on'; infers

export type ON = string;

Instead, we could infer it like

export type ON = 'on'

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
pluraliacommented, Nov 4, 2022

Not a big fan of reintroducing enum rules to the grammar.

Okay, adding enums is not what we want. However, I’d anyway expect that MyEnum returns string: 'on' would generate a type on for MyEnum and not just a string. It’s like a enum with the only one element, and if for MyEnum returns string: 'on' | 'off' we generate a type 'on' | 'off', why not do the same for the only one type alternative?

1reaction
pluraliacommented, Nov 3, 2022

The case described in https://github.com/langium/langium/discussions/720 is where the user expects an enum behavior of a datatype rule and I can imagine a lot of cases where it is a good idea, so what about introducing an enum datatype rule?

@dhuebner, yes, I like this idea. For example, this

MyEnum returns string: ON | OFF;
enum MyRealEnum: ON | OFF;
ON returns string: 'on' ('and' 'on')*;
OFF returns string: 'off'+;

will generate

export type MyRealEnum = ON | OFF
export type MyEnum = string

So, addition a keyword enum restricts to use only data type rules in a union, and we can infer type like a union of these data type rules without tries to evaluate a pattern.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Type Inference - TypeScript
This kind of inference takes place when initializing variables and members, setting parameter default values, and determining function return types. In most ...
Read more >
Type Inference, Type Improvement, and Type Simplification in ...
the language, the typing rules, and the type inference algorithm (not to mention proofs of sound- ness and completeness in the system), all...
Read more >
Lecture 26: Type Inference and Unification - CS@Cornell
Type inference refers to the process of determining the appropriate types for expressions based on how they are used. For example, in the...
Read more >
CS345H: Programming Languages Lecture 12: Type Inference
In this rule, this type variable encodes the return type of the application. Thomas Dillig,. CS345H: Programming Languages Lecture 12: Type Inference.
Read more >
9.6. Type Inference — OCaml Programming - GitHub Pages
We introduce a fresh type variable 't for the type of the application expression. We use inference to determine the types of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found