'Typescript: Can't return child class instance from super class' function
I'm having trouble returning a child class object from a super class function. I have the following structure:
pizza.ts:
import { PineapplePizza } from './pineapple.pizza';
export class Pizza {
public putOn(Pineapple pineapple): Pizza {
// ...
return new PineapplePizza(pineapple);
// ...
}
}
pineapple.pizza.ts:
import { Pizza } from './pizza';
export class PineapplePizza extends Pizza {
// ...
}
But I keep getting this runtime error:
firefox:
ReferenceError: can't access lexical declaration 'Pizza' before initialization
chrome:
ReferenceError: 'Pizza' is not defined
Does anyone know how to fix that? Or is impossible to return a child class instance from a super class?
EDIT #1:
This might be due to circular importing. Is there a way to pre-declare a class, kind of like with c++? Or a way to control which file gets compiled first?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
