2016-08-01 163 views
1

我是新來的TypeScript和我有一個問題加載一個es6 javascript模塊。TypeScript聲明模塊類導出

我有以下的javascript文件

//TemplateFactory.js 
export class TemplateFactory{ 
    static getTemplate(module){ 

    } 
} 

,我創建以下文件d.ts

//TemplateFactory.d.ts 
declare module "TemplateFactory" { 
    export class TemplateFactory { 
     static getTemplate(module); 
    } 
} 

然而,當我導入JS模塊中的另一個TS文件我得到這個錯誤:

File ....TemplateFactory .d.ts is not a module

我在做什麼錯? 我使用打字稿1.8

回答

1

我已經設法解決這個問題。 這裏是我工作的代碼:

export declare class TemplateFactory { 
    static getTemplate(module: any): void; 
} 
0

試試這個,

//TemplateFactory.d.ts 

declare module TemplateFactory { 

    export class TemplateFactory { 
     static getTemplate(module); 
    } 
} 

不要使用引號。

+0

它工作。 。 – Gangz

+0

對不起。這不起作用。我找到了解決方案並添加了我自己的答案 –

相關問題