简体   繁体   中英

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 . Typescript is raising an error ("cannot find name 'ReadableStream'") during transpilation. I've narrowed the issue down even farther, as shown below.

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;

...results in this error:

> npm run build

src/index.ts:6:10 - error TS2304: Cannot find name 'ReadableStream'.

6 const s: ReadableStream= null;

Node global types are declared under NodeJS namespace . 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. You could file a bug. In the meantime, writing import ReadableStream = NodeJS.ReadableStream; in a global declaration file should work around the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM