Closed Cythia828 closed 4 months ago
Have you tried to use a cast from your ParseTree
instances to the ParserRuleContextWithAttr
type?
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.
TS Error: The type "ParseTree" is missing the following properties of the type "ParserRuleContext": start, stop, exception, copyFrom, and 20 other items. ts(2740).
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.
You make a good point. I'll give your suggestion some serious thought.
Hello~ There is a TS problem. When somewhere is using
ParserRuleContext
'schildren
,we can find the child's type is error.Because every item's type of children isParseTree
. 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.