我已经查看了所有互联网,但找不到针对我的新项目的解决方案。我正在使用simple-git
包,类型定义包括对ReadableStream
的几个引用。打字期间,打字稿引发错误(“找不到名称'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运行构建
src / index.ts:6:10-错误TS2304:找不到名称“ ReadableStream”。
6 const s:ReadableStream = null;
答案 0 :(得分:2)
Node global types are declared under NodeJS
namespace。应该是:
const s: NodeJS.ReadableStream = null;
答案 1 :(得分:1)
estus是对的。最初,在simple-git
类型定义中似乎是一个错误。您可以提交错误。同时,在全局声明文件中写入import ReadableStream = NodeJS.ReadableStream;
应该可以解决此问题。