在TypeScript中,d.ts声明文件中的 export='是什么意思

如题所述

Typescript (以下简称:ts) 有一个好处是,你可以将 ts 代码生成CommonJs规范、AMD规范,而这二者的规范中,且无法兼容,所以就有了 export =,将二者给统一,以至于让ts支持以上规范。
declare module "swiper" {
const swiper: {
new (element: Element | string, options?: SwiperOptions): Swiper;
};

export = swiper;
}

如果在CommonJS规范中:
const Swiper = require('swiper');

或者AMD规范中:
require(['swiper'], function(Swiper) {

});

当然,如果你的 @types 不需要支持上面两种规范,那就不需要 export =,因为对于 ts 而言,你只需要这样:

import { Swiper } from 'swiper'
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答