class constructor cannot be invoked without 'new
Asked Answered
C

0

9

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
Cystocele answered 1/5, 2017 at 20:7 Comment(1)
Code similar to this works fine on my system. So it must be some odd configuration issue on your end. Could you please post ideally a GitHub repo or Gist? Failing that, at least your package.json and tsconfig.json? (I realize this is from 2017 but hey nobody answered yet)Anthropometry

© 2022 - 2024 — McMap. All rights reserved.