gulp-typescript编译器在readonly修饰符上引发错误 [英] gulp-typescript compiler throws errors on readonly modifier

查看:111
本文介绍了gulp-typescript编译器在readonly修饰符上引发错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将我的应用程序升级为使用Angular 2 rc.6Angular Material 2 alpha 8-1.这些软件包依赖typescript 2,后者使用了新的readonly修饰符.

I've just upgraded my app to use Angular 2 rc.6 and Angular Material 2 alpha 8-1. These packages rely on typescript 2 and the latter makes use of the new readonly modifier.

我使用gulp-typescript编译我的.ts文件,现在我从使用readonly修饰符的文件中发现很多错误.例如,这一行:

I use gulp-typescript to compile my .ts files and I'm now getting a lot of errors from files that use the readonly modifier. For instance, this line:

readonly change: Observable<MdButtonToggleChange>;

在编译过程中引发以下错误:

Throws these errors during compilation:

错误TS1005:预期为'='.

error TS1005: '=' expected.

错误TS1005:;"预期的.

error TS1005: ';' expected.

错误TS1005:("为预期.

error TS1005: '(' expected.

我认为这可能是因为gulp-typescript内部使用了typescript 1.8.10,而后者没有readonly修饰符.

I think this is probably because gulp-typescript internally uses typescript 1.8.10, which does not have the readonly modifier.

我自己的代码都不使用readonly;唯一引发错误的文件是Angular 2 Material软件包中的第三方打字稿定义文件(.d.ts).有问题的文件都在我的nodes_module/文件夹中,并且我尝试通过在tsconfig.json中包含以下内容来忽略它们:

None of my own code uses readonly; The only files throwing errors are third-party typescript definition files (.d.ts) from Angular 2 Material packages. The files in question are all within my nodes_module/ folder, and I've tried to ignore them by having the following in tsconfig.json:

"exclude": [
  "node_modules",
  "typings"
]

错误仍然显示出来.

  • 我能解决这个问题吗?
  • 如果没有,是否有一种简单的方法可以使编译器忽略.d.ts文件?
  • Can I solve this?
  • If not, is there an easy way to get the compiler to ignore .d.ts files?

推荐答案

一种解决方案是向您的项目(npm install typescript@rc --save-dev)添加TypeScript 2.0.2 RC依赖项,并使用非官方的 typescript 选项:

One solution would be to add a TypeScript 2.0.2 RC dependency to your project (npm install typescript@rc --save-dev) and to pass it to gulp-typescript using the unofficial typescript option:

[...].pipe(ts({
    typescript: require('typescript')
}));

这篇关于gulp-typescript编译器在readonly修饰符上引发错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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