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';
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';
Share
Improve this question
edited Jun 1, 2017 at 16:22
Alfabravo
7,5896 gold badges49 silver badges83 bronze badges
asked May 16, 2017 at 17:50
TwoisTwois
5981 gold badge7 silver badges19 bronze badges
8
-
Can you post the code for
../index.ts
? Are you exportingclass A
asdefault
? – rossipedia Commented May 16, 2017 at 18:01 - @rossipedia I updated the question with the file structure and the content of index.ts files – Twois Commented May 16, 2017 at 18:18
- Why not reference classA directly in classB? import { classA } from '../classA/classA'; – Poku Commented May 16, 2017 at 18:36
- There are many folder in root, and it is simpler than write down the direct reference in every file. - But I take a try, may be this help me. – Twois Commented May 16, 2017 at 18:40
- 1 Do not put a solution in the question. Post it as an answer. – user663031 Commented May 16, 2017 at 19:03
2 Answers
Reset to default 2Import classA directly. Try this:
import { classA } from '../classA/classA';
export class classB extends classA {
constructor() {
super();
this.do();
}
private do(): void {
// do something
}
In the root index.ts file the order have to be:
export * from './classA';
export * from './classB';