Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

292
Views
class constructor cannot be invoked without 'new

I am trying to use a 3rd party typescript library(antlr - https://github.com/tunnelvisionlabs/antlr4ts) in my angular 2 project created using angular-cli. It's failing with this error class constructor MyLexer cannot be invoked without 'new. If you look at below code snippet , it's failing while making call to super();.Also Lexer.js is sitting in node_modules of antlr library.

I am not using babel in my project but I found this other stackoverflow post which has similar error as mine Babel error: Class constructor Foo cannot be invoked without 'new'. It says that due to the way ES6 classes work, you cannot extend a native class with a transpiled class. Is it somehow related to my issue as well? Please guide.

Code snippet

let inputStream = new ANTLRInputStream("sometext");
      let lexer = new MyLexer(inputStream); // it fails here
      let tokenStream = new CommonTokenStream(lexer);
      let parser = new MyParser(tokenStream);

MyLexer.ts (Generated code)

    export class MyLexer extends Lexer {
        constructor(input: CharStream) {
                super(input); // it fails here. 
                this._interp = new LexerATNSimulator(MyLexer._ATN, this);
            }    
        // more code
     }

Lexer.js (sitting in node_modules)

class Lexer extends Recognizer_1.Recognizer {
    constructor(input) {
        super();
//more code
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

That's quite surprising. I'm using the same approach like you in my node module antlr4-graps, which has ES6 set as transpilation target and everything is working very well. Take a closer look there. Maybe you can spot other signifcant differences between your code and mine. I assume you have the latest alpha of antlr4ts installed.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!