Skip to content
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

npm run langium:generate does not generate optional field in base class but does in derived class, resulting in TypeScript error #1247

Open
steve-hickman-epistimis opened this issue Oct 30, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@steve-hickman-epistimis

In the example below, the test Langium grammar contains, among other things, the following:

ConceptualEntity infers ConceptualEntity:
    ConceptualAssociation | 'centity' name=ID  (description=STRING )? (':' specializes=[ConceptualEntity:QN ] )? '{' composition+=ConceptualComposition * ('basis:' '[' basisEntity+=[ConceptualBasisEntity:QN ]+ ']' )? '};'  
;


ConceptualAssociation infers ConceptualAssociation:
    'cassoc' name=ID  (description=STRING )? (':' specializes=[ConceptualEntity:QN ] )? '{' composition+=ConceptualComposition * ('basis:' '[' ConceptualBasisEntity+=[ConceptualBasisEntity:QN ]+ ']' )? ('participants:' '[' participant+=ConceptualParticipant + ']' )? '};'  
;

Note that the field specializes is optional in both ConceptualEntity and ConceptualAssociation.

The generated ast.ts contains the following exports:

export interface ConceptualEntity extends AstNode {
    readonly $type: 'ConceptualAssociation' | 'ConceptualEntity';
    basisEntity: Array<Reference<ConceptualBasisEntity>>
    composition: Array<ConceptualComposition>
    description?: string
    name: string
    specializes: Reference<ConceptualEntity>
}

export interface ConceptualAssociation extends ConceptualEntity {
    readonly $type: 'ConceptualAssociation';
    composition: Array<ConceptualComposition>
    ConceptualBasisEntity: Array<Reference<ConceptualBasisEntity>>
    description?: string
    name: string
    participant: Array<ConceptualParticipant>
    specializes?: Reference<ConceptualEntity>
}

Note that the specializes field in the exported interface ConceptualEntity is not optional but is optional in the exported ConceptualAssociation interface. This inconsistency causes a Typescript error.

Langium version:
Package name:

Screenshot 2023-10-30 at 12 54 26 PM

Steps To Reproduce

  1. yo langium to create a new Langium project (see screenshot)
    Screenshot 2023-10-30 at 12 39 58 PM
  2. Substituting the Langium grammars in the linked files for the default grammar generated in the prior step
  3. npm run langium:generate to generate, among other things, the ast.ts content.

Link to code example:
Terminals.txt
test.txt
ast.ts.txt
Note: All file extensions changed to .txt because GitHub doesn't support .langium extensions
Find linked above 2 Langium grammar files (Terminals.txt and test.txt). Also find linked above ast.ts.txt, the ast.ts file generated

The current behavior

Base class specializes field is not optional

The expected behavior

Base class specializes field is optional

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant