我有一个用打字稿写的网络工作者。它可以从命令行编译良好。但是,当我尝试在Gulp中编译它时,出现奇怪的类型错误:
/.../node_modules/@types/hls.js/index.d.ts(357,17): error TS2304: Cannot find name 'SourceBuffer'.
/.../node_modules/@types/hls.js/index.d.ts(1716,27): error TS2304: Cannot find name 'AudioTrack'.
... (more like that)
我不知道这些类型来自何处;但是我认为它与父目录(运行node_modules/@types
的地方)中的gulpfile.js
有关,但是我不知道为什么打字稿编译器会在那儿查找。我的gulpfile的(希望)相关部分是:
const ts = require('gulp-typescript');
const tsWorkerProject = ts.createProject('src/app/workers/tsconfig.json');
// stuff...
const compileWorkers = (done) => {
return tsWorkerProject.src()
.pipe(tsWorkerProject())
.js.pipe(gulp.dest(paths.dist))
.on('error', err => {
console.error(err.toString());
done(err);
});
};
// more stuff...
我在工作目录中有tsconfig.json
:
{
"compilerOptions": {
"lib": ["webworker", "ScriptHost", "ES2018"],
"importHelpers": true,
"target": "es5",
"jsx": "react",
"sourceMap": true,
"inlineSources": true,
"diagnostics": true,
},
"files": ["./*.ts"],
}
types
下包含一个空的compilerOptions
数组。我的工作tsconfig.json
如下:{
"compilerOptions": {
"lib": ["webworker", "scripthost", "ES2015"],
"importHelpers": true,
"target": "es2015",
"jsx": "react",
"sourceMap": true,
"inlineSources": true,
"diagnostics": true,
"types": [],
},
"files": ["./*.ts"],
}