【问题标题】:Cannot find name 'ReadableStream' (simple-git, node)找不到名称“ReadableStream”(简单 git,节点)
【发布时间】:2019-01-23 20:20:43
【问题描述】:

我查看了所有互联网,但无法为我的新项目找到解决方案。我正在使用simple-git 包,类型定义包括对ReadableStream 的几个引用。 Typescript 在转译期间引发错误(“找不到名称 '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;

【问题讨论】:

    标签: javascript node.js typescript typescript-typings


    【解决方案1】:

    estus 是对的。最初,它看起来像是simple-git 类型定义中的错误。你可以提交一个错误。同时,在全局声明文件中写入import ReadableStream = NodeJS.ReadableStream; 应该可以解决该问题。

    【讨论】:

      【解决方案2】:

      Node global types are declared under NodeJS namespace。应该是:

      const s: NodeJS.ReadableStream = null;
      

      【讨论】:

        猜你喜欢
        • 2018-03-27
        • 2023-04-08
        • 1970-01-01
        • 2020-06-19
        • 2014-10-02
        • 2018-09-05
        • 2018-12-14
        • 1970-01-01
        • 2021-05-22
        相关资源
        最近更新 更多