Gulp - typescript compiler throws errors in readonly modifier

I just updated my application to use Angular 2 rc.6and Angular Material 2 alpha 8-1. These packages rely on typescript 2, and the latter uses a new modifier readonly.

I use gulp-typescriptto compile my .ts files, and now I got a lot of errors from files that use the modifier readonly. For example, this line:

readonly change: Observable<MdButtonToggleChange>;

Throws these errors at compile time:

error TS1005: '=' expected.

error TS1005: ';' expected.

error TS1005: '(' expected.

I think this is probably because gulp-typescriptinternally uses typescript 1.8.10one that does not have a modifier readonly.

None of my own codes use readonly; The only errors when downloading files are third-party typescript ( .d.ts) definition files from packages Angular 2 Material. All files are in my folder nodes_module/, and I tried to ignore them by pointing to the tsconfig.jsonfollowing:

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

Errors still appear.

  • Can this be solved?
  • If not, is there an easy way to make the compiler ignore files .d.ts?
+1
source share
2 answers

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

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

@cartant , . , , gulp-typescript typescript 2 typescript 1.8. :

1. typescript 2.0.2 devDependency package.json

"devDependencies": {    
  "gulp-typescript": "^2.13.6",
  "typescript": "^2.0.2",
}

2. npm install typescript@2.0.2

3. , gulp-typescript gulpfile.js

From:

var ts = require('gulp-typescript');
var tsProject = ts.createProject('tsconfig.json');

To:

var ts = require('gulp-typescript');
var tsProject = ts.createProject('tsconfig.json', {
    //Use TS version installed by NPM instead of gulp-typescript built-in
    typescript: require('typescript')
});

. : -)

+3

Source: https://habr.com/ru/post/1652808/


All Articles