下面的这种方式我可以理解,相当于一个模块暴露了多个接口。
declare module "abcde" {
export let a: number
export function b(): number
export namespace c{
let cd: string
}
}
但是,下面这个就看不懂了,export = 是什么意思?
declare module "swiper" {
const swiper: {
new (element: Element | string, options?: SwiperOptions): Swiper;
};
export = swiper;
}
Typescript (以下简称:ts) 有一个好处是,你可以将 ts 代码生成CommonJs规范、AMD规范,而这二者的规范中,且无法兼容,所以就有了
export =
,将二者给统一,以至于让ts支持以上规范。如果在CommonJS规范中:
或者AMD规范中:
当然,如果你的 @types 不需要支持上面两种规范,那就不需要
export =
,因为对于 ts 而言,你只需要这样: