TypeScript 1.5 ES6 modules & .d.ts files from DefinitelyTyped seem incompatible

不打扰是莪最后的温柔 提交于 2019-12-24 17:14:31

问题


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.

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?

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.


回答1:


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.

Use --target es5 --noLib and then bring in es6.lib.d.ts manually.



来源:https://stackoverflow.com/questions/31568198/typescript-1-5-es6-modules-d-ts-files-from-definitelytyped-seem-incompatible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!