|
|
|
|
|
by the_gipsy
3037 days ago
|
|
I used to think that classes get special treatment in typescript, because they both reference a type and a constructor function. But I recently found out that you can do the same by exporting a constructor function and it's type with the same name: module a: export type A = { a: string };
export const A : () => A = () => { return {a: string}; };
module b: import A from './a';
const a = A(); // a is of type A
This way you can completely ditch classes, and still only import a single type/constructor combo. Not having to use `new` means easier composition and generally going more in the direction of functional programming. |
|