TypeScript: Unexpected `A class must be declared after its base class.` error with class expression

TypeScript Version: 2.0.2

Code

let cat = new class extends class {
    speak() {
        return "???";
    }
} {
    speak() {
        return "meow";
    }
}();
console.log(cat.speak());

Expected behavior:

We can compile this code.

Actual behavior:

$ tsc -v
Version 2.0.2
$ tsc sample.ts
$ sample.ts(1,29): error TS2690: A class must be declared after its base class.

This code can compiled by tsc 2.0.0.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 15 (10 by maintainers)

Commits related to this issue

Most upvoted comments

Well actually it’s real case when you don’t use modules and you compile into single file. Looks like in some cases TSC is lost with solving dependencies. I have this issue with base class in one file / derived class in another.

I’m using TS 2.1 dev. Checking on 2.0 RC …

I don’t know, this sample is making me warm up to class based programming in JavaScript 😉 It’s great when everything is first class!