mike-lischke / antlr4ng

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

[TS Error]ParserRuleContext‘s children has error type #79

Closed Cythia828 closed 2 months ago

Cythia828 commented 3 months ago
image image

Hello~ There is a TS problem. When somewhere is using ParserRuleContext's children,we can find the child's type is error.Because every item's type of children is ParseTree. TS Error: Type 'ParseTree' cannot be assigned to type 'ParserRuleContextWithAttr'. The type "ParseTree" is missing the following properties of the type "ParserRuleContext": start, stop, exception, copyFrom, and 20 other items.

mike-lischke commented 3 months ago

Have you tried to use a cast from your ParseTree instances to the ParserRuleContextWithAttr type?

Cythia828 commented 3 months ago

The transform between ParserRuleContext and ParserRuleContextWithAttr's type has been done. Actually, it's a problem between ParseTree and ParserRuleContext. In my opinion, as ParserRuleContext's children, its item should be ParserRuleContext type, too.But it's ParseTree in fact.

image

TS Error: The type "ParseTree" is missing the following properties of the type "ParserRuleContext": start, stop, exception, copyFrom, and 20 other items. ts(2740).

mike-lischke commented 3 months ago

The member children can have parser rule nodes or terminal nodes, so it cannot just return ParserRuleContext[]. Instead you have to check which type a particular child has.

Cythia828 commented 3 months ago

You make a good point. I'll give your suggestion some serious thought.