mike-lischke / antlr4ng

Next Generation TypeScript runtime for ANTLR4
Other
66 stars 11 forks source link

fix: fixed getChild method of ParserRuleContext class #15

Closed AleiynikovPavel closed 6 months ago

AleiynikovPavel commented 6 months ago

Problem

Proposed changes

mike-lischke commented 6 months ago

Good analysis, thanks! Your patch adds another overload signature, but looking at antlr4ts we can make this even simpler, by changing the existing context type signature to type: new (...args: unknown[]). This type only has one task (and hence the parameters are not relevant): it is used to check if a child is of this type.

And given that both overloads of getChildhave an index as first parameter, this entire signature can be reduced to:

    public override getChild<T extends ParseTree>(i: number, type?: new (...args: unknown[]) => T): T | null {
        ...
    }

What do you think?

AleiynikovPavel commented 6 months ago

I think type: new (...args: unknown[]) is a very good proposal. Especially if we assume that in the future new classes may appear that implement the ParseTree interface. Already added a new commit.