Typescript is failing to reference factory created class. Here's an example code:
// factory.ts
export const createClass = () =>
class Model {
// ...
}
// ModelA.ts
import {createClass} from './factory';
export const ModelA = createClass();
let a: ModelA; // Cannot find name 'ModelA';
// other.ts
import {ModelA} from './ModelA';
new ModelA() // Cannot find name 'ModelA';
What am I doing wrong here?
If you are trying to get the insurance type for the class generated by the function then you can use the InstanceType conditional type.
export const createClass = () =>
class Model {
// ...
}
export const ModelA = createClass();
type ModelA = InstanceType<typeof ModelA>
let a: ModelA = new ModelA(); // ok
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With