[英]Cannot find name 'ReadableStream' (simple-git, node)
I've looked at all of the internets and cannot find a solution to this for my new project. 我查看了所有的互联网,无法为我的新项目找到解决方案。 I'm using the simple-git
package and the type definition includes a couple references to ReadableStream
. 我正在使用simple-git
包,类型定义包含一些对ReadableStream
引用。 Typescript is raising an error ("cannot find name 'ReadableStream'") during transpilation. Typescript在转换过程中引发了一个错误(“找不到名字'ReadableStream'”)。 I've narrowed the issue down even farther, as shown below. 我把问题缩小了甚至更远,如下所示。
package.json 的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 tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"lib": [
"esnext"
],
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": false,
}
}
./src/index.ts ./src/index.ts
const s: ReadableStream = null;
...results in this error: ...导致此错误:
> npm run build > npm run build
src/index.ts:6:10 - error TS2304: Cannot find name 'ReadableStream'. src / index.ts:6:10 - 错误TS2304:找不到名称'ReadableStream'。
6 const s: ReadableStream= null; 6 const s:ReadableStream = null;
Node global types are declared under NodeJS
namespace . 节点全局类型在NodeJS
名称空间下声明 。 It should be: 它应该是:
const s: NodeJS.ReadableStream = null;
estus is right. 马斯是对的。 To the original point, it looks like a mistake in the simple-git
type definitions. 原来,它看起来像是simple-git
类型定义中的一个错误。 You could file a bug. 你可以提交一个bug。 In the meantime, writing import ReadableStream = NodeJS.ReadableStream;
在此期间,编写import ReadableStream = NodeJS.ReadableStream;
in a global declaration file should work around the problem. 在全局声明文件中应解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.