When using ES6 module syntax to export a factory function which returns an instance of a class Typescript produce the following error:
error TS4060: Return type of exported function has or is using private name 'Paths'.
From paths.ts:
//Class scoped behind the export
class Paths {
rootDir: string;
constructor(rootDir: string) {
this.rootDir = rootDir;
};
};
//Factory function: returns instances of Paths
export default function getPaths(rootDir:string){
return new Paths(rootDir);
};
This legitimate ES6 javascript. However, the only work around i've found is to export the class. Which means when it is compiled to ES6 the Class is being exported defeating the purpose of scoping it in the module. e.g:
//Class now exported
export class Paths {
rootDir: string;
constructor(rootDir: string) {
this.rootDir = rootDir;
};
};
//Factory function: returns instances of Paths
export default function getPaths(rootDir:string){
return new Paths(rootDir);
};
Am I missing something? It seems to me that this pattern should be supported by typescript, especially in ES6 compilation where the pattern becomes more prominent.