You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The TypeScript target produces a visitor similar to the following:
exportdefaultclassFooVisitor<Result>extendsParseTreeVisitor<Result>{/** * Visit a parse tree produced by `FooParser.bar`. * @param ctx the parse tree * @return the visitor result */visitBar?: (ctx: BarContext)=>Result;}
When overridden as shown in the docs, the code doesn't work (override is never called) and the compiler will show an error explaining the reason:
TS2425: Class FooVisitor defines instance member property visitBar, but extended class CustomVisitor defines it as instance member function.
As a workaround, it is possible to switch to a property:
but I expect that the intent from the target is overloading, same as one would overload the visitor methods in plain JS target. To allow that, the target can be modified to
-export default class FooVisitor<Result> extends ParseTreeVisitor<Result> {+export default abstract class FooVisitor<Result> extends ParseTreeVisitor<Result> {
/**
* Visit a parse tree produced by `FooParser.bar`.
* @param ctx the parse tree
* @return the visitor result
*/
- visitBar?: (ctx: BarContext) => Result;+ visitBar?(ctx: BarContext) => Result;
}
The text was updated successfully, but these errors were encountered:
tpluscode
changed the title
[TypeScript]
[TypeScript] Class Visitor defines instance member property visit, but extended class defines it as instance member function.
Oct 24, 2024
The TypeScript target produces a visitor similar to the following:
When overridden as shown in the docs, the code doesn't work (override is never called) and the compiler will show an error explaining the reason:
As a workaround, it is possible to switch to a property:
but I expect that the intent from the target is overloading, same as one would overload the visitor methods in plain JS target. To allow that, the target can be modified to
The text was updated successfully, but these errors were encountered: