我有旧的JS代码,我想在TypeScript中使用它。
考虑我的档案:
webapiClient / index.js
module.exports = require("./rest");
webapiClient / index.d.ts
declare module "webapiClient" {
class Rest {
constructor(cfg?:{
prefix?: string;
batchGetRequests?: boolean
});
prefix: string;
setCfg(updatedCfgParams: {[key: string]: any}): void;
get<T>(path: string, params?:any, options?:any): Promise<T>;
post<T>(path: string, bodyObject?:any): Promise<T>;
put<T>(path: string, bodyObject?:any): Promise<T>;
remove<T>(path: string, bodyObject?:any): Promise<T>;
param(v:any):any;
processBatch(param:any, options?:any):Promise<any>;
getUrlParams(url:string, toLower?:boolean):Object;
getUrlParam(url:string, p:string):Object;
getUrl(path:string, query?:any):string;
getPath(path:string, query?:any):string;
many(ref, p):any;
}
export = Rest;
}
我使用以下代码导入我的模块:
import webClient = require("../webapiClient");
但是当我用webpack构建我的项目时,我收到一个错误:
error TS2306: File 'path/to/webapiClient/index.d.ts' is not a module.
怎么了?