![](/img/trans.png)
[英]How to declare a module in TypeScript with an object as default export
[英]TypeScript declare module for class export
我是TypeScript的新手,我在加載es6 javascript模塊時遇到問題。
我有以下javascript文件
//TemplateFactory.js
export class TemplateFactory{
static getTemplate(module){
}
}
我創建了以下d.ts文件
//TemplateFactory.d.ts
declare module "TemplateFactory" {
export class TemplateFactory {
static getTemplate(module);
}
}
但是,當我在另一個ts文件中導入js模塊時,我收到此錯誤:
文件.... TemplateFactory .d.ts不是一個模塊
我究竟做錯了什么? 我正在使用TypeScript 1.8
我設法解決了這個問題。 這是適合我的代碼:
export declare class TemplateFactory {
static getTemplate(module: any): void;
}
嘗試這個 ,
//TemplateFactory.d.ts
declare module TemplateFactory {
export class TemplateFactory {
static getTemplate(module);
}
}
不要使用引號。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.