TypeScript 错误“TS2354:此语法需要导入的帮助程序,但无法找到模块“tslib””

dob*_*ler 6 typescript

我已将 TypeScript 的问题简化为以下示例。尝试运行 tsc 时,我收到以下错误消息,但tslib应该可用。

https://codesandbox.io/s/quizzical-mclean-n9vvi?fontsize=14&hidenavigation=1&theme=dark

$ tsc --noEmit --project ./tsconfig.json

index.js:3:8 - error TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.

3 const {ArgumentParser} = require('argparse');
         ~~~~~~~~~~~~~~
Found 1 error.
Run Code Online (Sandbox Code Playgroud)

包.json

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.ts",
  "scripts": {
    "test": "tsc --noEmit --project ./tsconfig.json"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/argparse": "1.0.38",
    "argparse": "1.0.10",
    "tslib": "1.11.1",
    "typescript": "3.8.3"
  }
}
Run Code Online (Sandbox Code Playgroud)

tsconfig.json

{
  "compilerOptions": {
    "checkJs": true,
    "allowJs": true,
    "moduleResolution": "node",
    "target": "es2018",
    "module": "commonjs",
    "importHelpers": true,
    "lib": [
      "es2018"
    ]
  },
  "include": [
    "*.js"
  ],
  "exclude": [
    "node_modules"
  ]
}
Run Code Online (Sandbox Code Playgroud)

索引.js

'use strict';

const {ArgumentParser} = require('argparse');
Run Code Online (Sandbox Code Playgroud)

dob*_*ler 3

该问题现已被确认为 TypeScript 中的错误https://github.com/microsoft/TypeScript/issues/37991