typescript extend class with imported class

Viewed 4042

If I extend a locally exported class, it works.

Working example:

export class classA {

    constructor() {
        super();
    }
}

export class classB extends classA {

constructor() {
    super();

    this.do();
}

private do(): void {
    // do something
}

But when I import classA from outside of the file it's not work.

not Working example:

import { classA } from '../'; // I use index.ts file, so the reference is good.

export class classB extends classA {
    constructor() {
        super();

        this.do();
    }

    private do(): void {
        // do something
    }
}

File structure:

Root/
- index.ts

- classA(folder)/
   - index.ts
   - classA.ts

- classB(folder)/
   - index.ts
   - classB.ts

The index.ts file inside classA folder:

export * from './classA';

The root index.ts file:

export * from './classB';
export * from './classA';

Error message: class classB extends _1.classA TypeError: Class extends value undefined is not a constructor or null

I need to load outside from this file, because I would like to use classA in other files... Any idea why happen this?

[Solved]: In the root index.ts file the order have to be:

export * from './classA';
export * from './classB';
2 Answers
Related