Dynamically load classes
Use case: extend functionality by just adding a new file into a folder.
Interface
To be type safe it's recommended to implement an interface:
export interface MyInterface {
some_function: (input: MyType) => void;
another_function: (input: MyType2) => string;
}Classes to be imported
// myClass.ts
export default class MyClass implements MyInterface {
async some_function(input: MyType) {
// ...
}
another_function(input: MyType2) {
// ...
}
}Loader
Last updated