gulp-typescript编译器在readonly修饰符上引发错误 [英] gulp-typescript compiler throws errors on readonly modifier
问题描述
我刚刚将我的应用程序升级为使用Angular 2 rc.6
和Angular 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屋!