Typescript: "A class must be declared after its base class" on classes in different directories

Created on 16 Aug 2016  路  2Comments  路  Source: microsoft/TypeScript

TypeScript Version: master branch

Repro

  1. Create a new JavaScript->Windows->Universal->Blank App project
  2. Add directories and empty files as following:

```
(App name)
|>sources
| |>cats
| | |>elephants
| | | foo.ts
| | bar.ts

sources/cats/elephants/foo.ts
sources/cats/bar.ts
```

  1. Write codes as following:

``` ts
// In sources/cats/elephants/foo.ts:
class Foo extends Bar {
}

// In sources/cats/bar.ts:
class Bar {
}
```

  1. Open project properties and set "Combine JavaScript output into file" to "js/app.js"
  2. Unload project
  3. Reload project

Expected behavior:

Compiler should automatically make a proper order for the classes

Actual behavior:

class Foo extends Bar {
//                ~~~
//                A class must be declared after its base class.
}

Workaround:

Rename "foo.ts" to "a.ts".

Question

Most helpful comment

The compiler doesn't figure out what the "right" order of files is based on class dependencies or anything else. The usual methods are available: have a _reference.ts, use /// <reference directives, or use a module loader (if applicable)

All 2 comments

The compiler doesn't figure out what the "right" order of files is based on class dependencies or anything else. The usual methods are available: have a _reference.ts, use /// <reference directives, or use a module loader (if applicable)

Thanks! I would be happier if the error message told me the tip.

Was this page helpful?
0 / 5 - 0 ratings