【问题标题】:TypeScript version not compatible with Angular 11 after generating client code生成客户端代码后,TypeScript 版本与 Angular 11 不兼容
【发布时间】:2021-04-18 20:24:12
【问题描述】:

我无法编译生成的客户端,因为 TypeScript 版本与 Angular 11 不兼容:

ERROR: The Angular Compiler requires TypeScript >=4.0.0 and <4.1.0 but 3.5.3 was found instead.

如何在生成代码时设置正确的 TypeScript 版本?这就是我定义 gradle 任务的方式:

openApiGenerate {
    generatorName = 'typescript-angular'
    inputSpec = swaggerFilePath
    outputDir = apiClientOutputDir
    configOptions = [
            npmName   : 'rest-client',
            npmVersion: '0.0.0',
            ngVersion: '11.0.6'
    ]
}

这是写入rest-client 模块的package.json 文件的内容。

  "devDependencies": {
    "@angular/common": "^11.0.6",
    "@angular/compiler": "^11.0.6",
    "@angular/compiler-cli": "^11.0.6",
    "@angular/core": "^11.0.6",
    "@angular/platform-browser": "^11.0.6",
    "ng-packagr": "^5.4.0",
    "reflect-metadata": "^0.1.3",
    "rxjs": "^6.5.0",
    "tsickle": "^0.35.0",
    "typescript": ">=3.4.0 <3.6.0",
    "zone.js": "^0.9.1"
  }

我的依赖:

// Spring Docs
implementation 'org.springdoc:springdoc-openapi-ui:1.5.2'
implementation 'org.springdoc:springdoc-openapi-data-rest:1.5.2'

【问题讨论】:

  • npm i -D typescript@^4.0.0
  • 能否请您检查所有依赖项,它们似乎已经过时了,并且 Angular 使用不同的更高版本。您是否应该通过npm outdated 检查这些内容,以便检查是否应该更新某些内容。
  • @GetOffMyLawn 我不确定,但我认为 Angular 11 需要 typescript &gt;=3.4.0 &lt;3.6.0。使用 >=4.0.0 无效。
  • 错误消息显示TypeScript &gt;=4.0.0 and &lt;4.1.0。因此,4.0.x 的版本应该可以解决该错误消息。
  • 其实Angular 11需要使用TS 4及以上stackoverflow.com/a/57216166/10959940

标签: typescript openapi openapi-generator springdoc


【解决方案1】:

问题是我使用的 OpenAPI 生成器版本过时,不了解 Angular 11。

变化

id 'org.openapi.generator' version '4.2.2'

id 'org.openapi.generator' version '5.0.0'

解决了这个问题。

我此时也将我的 Spring Doc 依赖升级到了最新版本:

// Spring Docs
implementation 'org.springdoc:springdoc-openapi-ui:1.5.2'
implementation 'org.springdoc:springdoc-openapi-data-rest:1.5.2'

【讨论】:

    猜你喜欢
    • 2011-08-25
    • 1970-01-01
    • 2010-10-14
    • 2021-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-31
    • 1970-01-01
    相关资源
    最近更新 更多