typescripttypescript-typingsgulp-typescripttypescript2.0

gulp-typescript and typescript's new @types typings?


I have installed @types/jasmine as a devDependency.

My gulp task to compile my typescript is like so:

gulp.task('compile:tests', ['compile:typescript', 'clean:tests'], function () {
    var project = ts.createProject('tsconfig.json', { typescript: typescript });

    var tsResult = gulp.src(['spec/**/*spec.ts'])
        .pipe(ts(project));

    return tsResult.js
        .pipe(gulp.dest('spec/'));
});

and my tsconfig.json

{
    "compilerOptions": {
        "target": "es6",
        "module": "commonjs",
        "moduleResolution": "node"
    },
    "exclude": [
        "node_modules"
    ]
}

but this results in the errors:

spec\linter.spec.ts(7,1): error TS2304: Cannot find name 'describe'.
spec\linter.spec.ts(8,3): error TS2304: Cannot find name 'it'.
spec\linter.spec.ts(17,5): error TS2304: Cannot find name 'expect'.
spec\linter.spec.ts(20,3): error TS2304: Cannot find name 'it'.

How can I get typescript (when used by gulp-typescript) to recognize the @types/... typings?


Solution

  • Updated: latest version fixes the issue: install with

    npm install gulp-typescript@3

    pre gulp-typescript@3: So far my work around has been to manually include all @types typings, like so:

    gulp.src(['spec/**/*spec.ts', "./node_modules/@types/**/*.d.ts"])
    

    if you have conflicting versions of typings (here's looking at you @types/node@x) then you can skip over them to avoid the duplicates:

    gulp.src([
      paths.source + '**/*.ts', 
      "node_modules/@types/**/index.d.ts", 
      "!node_modules/@types/**/node_modules/**/index.d.ts"])