我've looked at all of the internets and cannot find a solution to this for my new project. I'm使用 simple-git
包,类型定义包括对 ReadableStream
的几个引用 . 打字稿期间,Typescript会引发错误("cannot find name 'ReadableStream'") . 我把问题缩小了甚至更远,如下所示 .
package.json
{
"name": "my-project",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"build": "./node_modules/.bin/tsc",
"watch": "./node_modules/.bin/tsc --watch"
},
"devDependencies": {
"@types/node": "^10.7.1",
"@types/yargs": "^11.1.1",
"typescript": "^3.0.1"
},
"dependencies": {
"fs": "0.0.1-security",
"simple-git": "^1.96.0",
"yargs": "^12.0.1"
}
}
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"lib": [
"esnext"
],
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": false,
}
}
./src/index.ts
const s: ReadableStream = null;
...导致此错误:
npm run build src / index.ts:6:10 - 错误TS2304:找不到名称'ReadableStream' . 6 const s:ReadableStream = null;
2 回答
马斯是对的 . 原来,它看起来像
simple-git
类型定义中的错误 . 你可以提交一个bug . 与此同时,在全局声明文件中编写import ReadableStream = NodeJS.ReadableStream;
应解决此问题 .Node global types are declared under NodeJS namespace . 它应该是: