Support strictmode in Typescript target #4090
ChrisLincoln
started this conversation in
General
Replies: 2 comments 3 replies
-
So you want to explicitly turn strict mode off for the generated files ?Envoyé de mon iPhoneLe 29 janv. 2023 à 16:41, ChrisLincoln ***@***.***> a écrit :
I've modified the Dockerfile to be able to use the head of the dev branch so I can try out the new Typescript target. I have a TS project with strict mode turned on. The generated lexer.ts and parser.ts contain code that will not compile in strict mode. For example, using the sample arithmetic grammer, you get these:
public static readonly literalNames: string[] = [ null, null, null, "'('",
"')'", "'+'", "'-'",
"'*'", "'/'", "'>'",
"'<'", "'='", "'.'",
"'^'" ];
To pass in strict mode, these should be (string|null)[]. Also, the generated code is passing class types in the calls to getTypedRuleContext(), which seems correct per the underlying runtime javascript, but is throwing strict mode errors:
public equation_list(): EquationContext[] {
return this.getTypedRuleContexts(EquationContext) as EquationContext[];
}
arithmeticParser.ts:486:36 - error TS2345: Argument of type 'typeof EquationContext' is not assignable to parameter of type 'new (parser?: Parser | undefined, parent?: ParserRuleContext | undefined, invokingState?: number | undefined, ...args: any[]) => EquationContext'.
Types of construct signatures are incompatible.
Type 'new (parser?: arithmeticParser | undefined, parent?: ParserRuleContext | undefined, invokingState?: number | undefined) => EquationContext' is not assignable to type 'new (parser?: Parser | undefined, parent?: ParserRuleContext | undefined, invokingState?: number | undefined, ...args: any[]) => EquationContext'.
Types of parameters 'parser' and 'parser' are incompatible.
Type 'Parser | undefined' is not assignable to type 'arithmeticParser | undefined'.
Type 'Parser' is missing the following properties from type 'arithmeticParser': grammarFileName, literalNames, symbolicNames, ruleNames, and 11 more.
486 return this.getTypedRuleContexts(EquationContext) as EquationContext[];
I don't really know how to fix those. If I could turn off strict mode for just these files, I would and not worry about it because I inherently trust in their goodness as auto-generated code. But I can't turn it off. I suppose I could spin off a "shared" project and turn off strict mode in its compilation.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
3 replies
-
beta 10 brings some minor tweaks |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've modified the Dockerfile to be able to use the head of the dev branch so I can try out the new Typescript target. I have a TS project with strict mode turned on. The generated lexer.ts and parser.ts contain code that will not compile in strict mode. For example, using the sample arithmetic grammer, you get these:
To pass in strict mode, these should be (string|null)[]. Also, the generated code is passing class types in the calls to getTypedRuleContext(), which seems correct per the underlying runtime javascript, but is throwing strict mode errors:
I don't really know how to fix those. If I could turn off strict mode for just these files, I would and not worry about it because I inherently trust in their goodness as auto-generated code. But I can't turn it off. I suppose I could spin off a "shared" project and turn off strict mode in its compilation.
Beta Was this translation helpful? Give feedback.
All reactions