[英]gulp-typescript and typescript's new @types typings?
I have installed @types/jasmine
as a devDependency. 我已经将@types/jasmine
安装为devDependency。
My gulp task to compile my typescript is like so: 我编写我的打字稿的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/'));
});
and my tsconfig.json 和我的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(7,1):错误TS2304:找不到名称'describe'。
spec\\linter.spec.ts(8,3): error TS2304: Cannot find name 'it'. spec \\ linter.spec.ts(8,3):错误TS2304:找不到名称'it'。
spec\\linter.spec.ts(17,5): error TS2304: Cannot find name 'expect'. spec \\ linter.spec.ts(17,5):错误TS2304:找不到名称'expect'。
spec\\linter.spec.ts(20,3): error TS2304: Cannot find name 'it'. spec \\ linter.spec.ts(20,3):错误TS2304:找不到名称'it'。
How can I get typescript (when used by gulp-typescript) to recognize the @types/...
typings? 如何获取打字稿(当由@types/...
- @types/...
使用时)识别@types/...
?
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: pre gulp-typescript @ 3:到目前为止,我的工作是手动包含所有@types类型,如下所示:
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: 如果你有类型的冲突版本(这里是你看@types/node@x
),那么你可以跳过它们以避免重复:
gulp.src([
paths.source + '**/*.ts',
"node_modules/@types/**/index.d.ts",
"!node_modules/@types/**/node_modules/**/index.d.ts"])
You can use project.src()
instead of gulp.src(['typings-glob', 'sources-glob'])
. 您可以使用project.src()
而不是gulp.src(['typings-glob', 'sources-glob'])
。
** For some reason, in project I'm working on, transpilation takes ~3 seconds more when project.src()
used, so I stick with the gulp.src
option. **出于某种原因,在我正在进行的项目中,当使用project.src()
时,转换需要大约3秒钟,所以我坚持使用gulp.src
选项。
The following work for me. 以下为我工作。
{ "compilerOptions": { "target": "es6", "module": "commonjs", "moduleResolution": "node" }, "files": [ "node_modules/@types/**/*.d.ts" ], "exclude": [ "node_modules" ] }
nvm, that wont work, neither does using "include" and "exclude" together. nvm,不会工作,也不会同时使用“包含”和“排除”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.