Typescript 我可以从TS 2.x导入用TS 1.x书写的打字吗?
我几天前开始学习Typescript,到目前为止,它相当混乱,尤其是在模块方面 我正在使用npm install-s@types/knockout导入打字,但是大多数可用的打字仍然是用Typescript 1编写的 以下是es6 promise软件包中的键入定义:Typescript 我可以从TS 2.x导入用TS 1.x书写的打字吗?,typescript,systemjs,commonjs,babeljs,typescript-typings,Typescript,Systemjs,Commonjs,Babeljs,Typescript Typings,我几天前开始学习Typescript,到目前为止,它相当混乱,尤其是在模块方面 我正在使用npm install-s@types/knockout导入打字,但是大多数可用的打字仍然是用Typescript 1编写的 以下是es6 promise软件包中的键入定义: declare module 'es6-promise' { var foo: typeof Promise; // Temp variable to reference Promise in local context namesp
declare module 'es6-promise' {
var foo: typeof Promise; // Temp variable to reference Promise in local context
namespace rsvp {
export var Promise: typeof foo;
export function polyfill(): void;
}
export = rsvp;
}
是否有方法从typescript 2导入指定为
export=xxx
的默认导出?是的,您可以使用它们。不幸的是,TypeScript对ES模块采用了向后看的方法,而不是向前看的方法
export = rsvp
不是默认的导出
默认导出的格式为
export default rsvp;
export=
是一个特定于TypeScript CommonJS的构造,它意味着分配给模块。export
属性可用于CommonJS模块
为了将其作为默认值导入,您需要做两件事
“allowsyntheticdefaultimports”:true