TypeScript 1.5 ES6模块&来自DefinitelyTyped的.d.ts文件似乎不兼容 [英] TypeScript 1.5 ES6 modules & .d.ts files from DefinitelyTyped seem incompatible

查看:247
本文介绍了TypeScript 1.5 ES6模块&来自DefinitelyTyped的.d.ts文件似乎不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WebStorm进行网页开发和最近从内置的TypeScript 1.4编译器升级到1.5.3。但是,并不是一切都按照我想要的,因为编译器开始出现错误提示我删除 - module commonjs parameter&切换到ES6模块(我使用 - 目标es6 )。做到这一点,我开始收到错误,指出导入作业不能用于瞄准ES6&我应该使用新的模块语法(错误1202)。所以我转换了所有的文件,但显然这是不够的,因为通过 tsd 安装的 .d.ts 从DefinitelyTyped repo使用旧的语法,使编译器不断提供相同的错误。

I'm using WebStorm for web-development & have recently upgraded from the built-in TypeScript 1.4 compiler to 1.5.3. However, not everything went as I wanted as the compiler began to yield errors prompting me to drop the --module commonjs parameter & switch to ES6 modules instead (I'm using --target es6). Having done that, I started getting errors saying that import assignments cannot be used when targeting ES6 & that I should use the new module syntax instead (error 1202). So I converted all my files, but apparently it wasn't enough as the .d.ts files installed via tsd from the DefinitelyTyped repo use the old syntax making the compiler keep giving the same errors.

我为 .d.ts 文件,它的工作相当不错,但偶尔会使我手动修复错误&那里。我想知道是否有更好的解决方法?也许,我错过了什么?

I wrote a small converter for the .d.ts files, it works fairly well although occasionally makes me fix errors manually here & there. I'm wondering if there is a better workaround for this? Perhaps, I'm missing something?

- 目标更改为 es5 不是一个选项,因为编译器否则会抱怨不存在诸如承诺我在我的项目中大量使用。

P.S. Changing the --target to es5 is not an option as the compiler would otherwise complain about absence of things like promises which I heavily use in my project.

推荐答案


将--target更改为es5不是一个选项因为编译器否则会抱怨我没有像我在项目中大量使用的承诺这样的事情。

Changing the --target to es5 is not an option as the compiler would otherwise complain about absence of things like promises which I heavily use in my project.

使用 --target es5 --noLib 然后手动引入 es6.lib.d.ts

这篇关于TypeScript 1.5 ES6模块&来自DefinitelyTyped的.d.ts文件似乎不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆