mike-lischke / antlr4ng

Next Generation TypeScript runtime for ANTLR4
Other
85 stars 15 forks source link

getRuleContext is incompatible with generated code (2.0.5) #26

Closed EliotVU closed 8 months ago

EliotVU commented 8 months ago

As seen in this screenshot: image

The generated code is incompatible with the declared method "getRuleContext", e.g. Argument of type 'typeof IdentifierContext' is not assignable to parameter of type 'new (...args: unknown[]) => IdentifierContext'.ts(2345)

mike-lischke commented 8 months ago

Odd, that was changed in this commit, to allow any constructor. And this change has been published in 2.0.5.

And looking at the bundle I see that code there. Are you sure you have 2.0.5 in your project?

EliotVU commented 8 months ago

That was my thought at first too, I have confirmed the code is that of 2.0.5, also you can tell by the screenshot's error popup it lists the new type as seen in your commit. :/

mike-lischke commented 8 months ago

Can you post your IdentifierContext class here? Is there something unusual in its constructor?

Try also changing the typings file to use ...args?: unknown[] instead.

EliotVU commented 8 months ago

I fixed it by changing the type from unknown to any.

As for IdentifierContext its constructor is the default, this error is occurring for all context derivatives.

export class IdentifierContext extends antlr.ParserRuleContext {
    public constructor(parent: antlr.ParserRuleContext | null, invokingState: number) {
        super(parent, invokingState);
    }
}
mike-lischke commented 8 months ago

Meanwhile I saw this in one of my projects too and tbh. I'm totally perplexed. The behavior is different depending on the project, even though the context signatures are the same. All deps are at their latest version (particularly TypeScript) and I don't understand why one project works and the other does not.

Console-buche commented 8 months ago

Hi there, Quick note to let you know we've also had this issue and patched it to any temporarily.

mike-lischke commented 8 months ago

This is fixed in 2.0.10