Typescript 编译问题(ES2015 --lib 选项)

问题描述 投票:0回答:0

使用

tsc -p .
编译打字稿文件时出现以下错误

错误 TS2705:ES5/ES3 中的异步函数或方法需要 “承诺”构造函数。确保你有一份声明 “承诺”构造函数或在“--lib”选项中包含“ES2015”。

9 异步函数 fetchImages(param1: string): Promise {

//"lib": ["ES2015"],
添加到 tsconfig.json 并不能解决它。

最终通过将“@types/node”:“^20.1.3”添加到我的依赖项来修复它,但是有人可以解释更多关于 --lib 选项的信息以及如何修复它,因为它没有我的情况。

或者错误是指不同的 lib 选项?

node -v
v19.9.0

tsc -v                    
Version 5.1.0-dev.20230512

ts配置:

{
  "compilerOptions": {
    /* Visit https://aka.ms/tsconfig to read more about this file */

    /* Language and Environment */
    "target": "es5",                                  /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */

    /* Modules */
    "module": "es6",                                /* Specify what module code is generated. */
    "rootDir": ".",                                  /* Specify the root folder within your source files. */
    "baseUrl": ".",                                  /* Specify the base directory to resolve non-relative module names. */

    /* Emit */
    "sourceMap": true,                                /* Create source map files for emitted JavaScript files. */
    "outDir": "dist",                                   /* Specify an output folder for all emitted files. */

    /* Interop Constraints */
    "esModuleInterop": true,                             /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
    "forceConsistentCasingInFileNames": true,            /* Ensure that casing is correct in imports. */

    /* Type Checking */
    "strict": true,                                      /* Enable all strict type-checking options. */
    
    /* Completeness */
    "skipLibCheck": true                                 /* Skip type checking all .d.ts files. */
  }
}
node.js typescript node-modules tsconfig
© www.soinside.com 2019 - 2024. All rights reserved.