gulp-typescript 和 typescript 的新@types 打字?
gulp-typescript and typescript's new @types typings?
我已将 @types/jasmine
安装为 devDependency。
我的 gulp 编译打字稿的任务是这样的:
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/'));
});
和我的tsconfig.json
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node"
},
"exclude": [
"node_modules"
]
}
但这会导致错误:
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'.
我如何获得打字稿(当被 gulp-打字稿使用时)来识别 @types/...
打字?
更新:
最新版本修复了这个问题:安装
npm install gulp-typescript@3
pre gulp-typescript@3:
到目前为止,我的工作是手动包含所有@types 类型,如下所示:
gulp.src(['spec/**/*spec.ts', "./node_modules/@types/**/*.d.ts"])
如果您的打字版本有冲突(这里指的是您 @types/node@x
),那么您可以跳过它们以避免重复:
gulp.src([
paths.source + '**/*.ts',
"node_modules/@types/**/index.d.ts",
"!node_modules/@types/**/node_modules/**/index.d.ts"])
您可以使用 project.src()
而不是 gulp.src(['typings-glob', 'sources-glob'])
。
** 出于某种原因,在我正在处理的项目中,当使用 project.src()
时,转译需要大约 3 秒的时间,所以我坚持使用 gulp.src
选项。
下面的工作对我来说。
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node"
},
"files": [
"node_modules/@types/**/*.d.ts"
],
"exclude": [
"node_modules"
]
}
nvm,那行不通,同时使用 "include" 和 "exclude" 也行不通。
我已将 @types/jasmine
安装为 devDependency。
我的 gulp 编译打字稿的任务是这样的:
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/'));
});
和我的tsconfig.json
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node"
},
"exclude": [
"node_modules"
]
}
但这会导致错误:
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'.
我如何获得打字稿(当被 gulp-打字稿使用时)来识别 @types/...
打字?
更新: 最新版本修复了这个问题:安装
npm install gulp-typescript@3
pre gulp-typescript@3: 到目前为止,我的工作是手动包含所有@types 类型,如下所示:
gulp.src(['spec/**/*spec.ts', "./node_modules/@types/**/*.d.ts"])
如果您的打字版本有冲突(这里指的是您 @types/node@x
),那么您可以跳过它们以避免重复:
gulp.src([
paths.source + '**/*.ts',
"node_modules/@types/**/index.d.ts",
"!node_modules/@types/**/node_modules/**/index.d.ts"])
您可以使用 project.src()
而不是 gulp.src(['typings-glob', 'sources-glob'])
。
** 出于某种原因,在我正在处理的项目中,当使用 project.src()
时,转译需要大约 3 秒的时间,所以我坚持使用 gulp.src
选项。
下面的工作对我来说。
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node"
},
"files": [
"node_modules/@types/**/*.d.ts"
],
"exclude": [
"node_modules"
]
}
nvm,那行不通,同时使用 "include" 和 "exclude" 也行不通。