相关疑难解决方法(0)

打字稿块节点/模块工厂模式:错误TS4060

使用ES6模块语法导出返回类Typescript实例的工厂函数时,会产生以下错误:

错误TS4060:导出函数的返回类型具有或正在使用私有名称"路径".

来自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);

};
Run Code Online (Sandbox Code Playgroud)

这个合法的ES6 javascript.但是,我发现的唯一工作就是出口课程.这意味着当它被编译到ES6时,正在导出类,从而无法在模块中确定范围.例如:

//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);

};
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?在我看来,这个模式应该由打字稿支持,特别是在ES6编译中,模式变得更加突出.

typescript ecmascript-6 es6-module-loader

3
推荐指数
1
解决办法
587
查看次数