【发布时间】:2019-03-30 11:15:23
【问题描述】:
我正在构建一个可以在 JS 和 TS 中使用的模块。
据我所知,在JS中创建模块时,需要创建一个单独的d.ts文件。(当然可以使用TS编译成JS)。无论如何,我选择制作d.ts 文件。
例如。
// common.d.ts
declare namespace common {
export const method: string => string;
}
export = common;
接下来,
// utils.d.ts
import * as u from './common';
declare namespace utils {
export const common: u // Causing an error.
}
export = utils;
我得到了这个错误:The namespace 'u' can not be used as a format.
我想写这个来统一导入地址。
import { common as u } from '/utils';
u.method('Any params');
我想,也许我可以从t.ds 文件中获取声明并分配它们。但是我不知道怎么做。谁能帮帮我!
【问题讨论】:
标签: typescript import namespaces export declare