错误 TS2707 通用类型“ɵɵDirectiveDeclaration”需要 6 到 8 个类型参数

2024-02-08

安装角度材料并将角度材料导入 app.module.ts 添加到项目后,我遇到错误,并且到目前为止所有解决方案都不起作用。我的角度为 14,节点为 16。第一个错误,实际上要长得多:

Error: node_modules/@angular/cdk/a11y/index.d.ts:152:18 - error TS2707: Generic type 'ɵɵDirectiveDeclaration' requires between 6 and 8 type arguments.

152     static ɵdir: i0.ɵɵDirectiveDeclaration<CdkAriaLive, "[cdkAriaLive]", ["cdkAriaLive"], { "politeness": "cdkAriaLive"; "duration": "cdkAriaLiveDuration"; }, {}, never, never, false, never>;
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Error: node_modules/@angular/cdk/a11y/index.d.ts:175:18 - error TS2707: Generic type 'ɵɵDirectiveDeclaration' requires between 6 and 8 type arguments.

175     static ɵdir: i0.ɵɵDirectiveDeclaration<CdkMonitorFocus, "[cdkMonitorElementFocus], [cdkMonitorSubtreeFocus]", ["cdkMonitorFocus"], {}, { "cdkFocusChange": "cdkFocusChange"; }, never, never, false, never>;
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Error: node_modules/@angular/cdk/a11y/index.d.ts:208:18 - error TS2707: Generic type 'ɵɵDirectiveDeclaration' requires between 6 and 8 type arguments.

208     static ɵdir: i0.ɵɵDirectiveDeclaration<CdkTrapFocus, "[cdkTrapFocus]", ["cdkTrapFocus"], { "enabled": "cdkTrapFocus"; "autoCapture": "cdkTrapFocusAutoCapture"; }, {}, never, never, false, never>;
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Error: node_modules/@angular/cdk/bidi/index.d.ts:37:18 - error TS2707: Generic type 'ɵɵDirectiveDeclaration' requires between 6 and 8 type arguments.

37     static ɵdir: i0.ɵɵDirectiveDeclaration<Dir, "[dir]", ["dir"], { "dir": "dir"; }, { "change": "dirChange"; }, never, never, false, never>;
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




{
  "name": "highlight",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^14.2.4",
    "@angular/cdk": "^15.0.0",
    "@angular/common": "^14.2.4",
    "@angular/compiler": "^14.2.4",
    "@angular/core": "^14.2.4",
    "@angular/forms": "^14.2.4",
    "@angular/material": "^15.0.0",
    "@angular/platform-browser": "^14.2.4",
    "@angular/platform-browser-dynamic": "^14.2.4",
    "@angular/router": "^14.2.4",
    "@fortawesome/angular-fontawesome": "^0.11.1",
    "@fortawesome/fontawesome-svg-core": "^6.2.0",
    "@fortawesome/free-solid-svg-icons": "^6.2.0",
    "@ng-bootstrap/ng-bootstrap": "^13.0.0",
    "@popperjs/core": "^2.11.6",
    "@syncfusion/ej2-angular-calendars": "^20.3.56",
    "apexcharts": "^3.36.3",
    "bootstrap": "^5.2.2",
    "jwt-decode": "^3.1.2",
    "ng-apexcharts": "^1.7.4",
    "rxjs": "~6.6.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^14.2.4",
    "@angular/cli": "^14.2.4",
    "@angular/compiler-cli": "^14.2.4",
    "@angular/localize": "^14.2.4",
    "@types/jasmine": "~3.8.0",
    "@types/node": "^12.11.1",
    "jasmine-core": "~3.8.0",
    "karma": "~6.3.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.0.3",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "~1.7.0",
    "typescript": "4.7"
  }
}

我尝试删除node_modules、.angular 和npm install。没用。 接下来我尝试重新安装角度材料 - npm install --save @angular/material @angular/cdk - 给了我错误,但不同的错误。我怀疑这显示了我实际错误的更清楚的原因。正如错误中所建议的,我尝试了命令 npm install --legacy-peer-deps, --force, npm install --save --legacy-peer-deps ,但不起作用。也许有人有更多经验并认识到这个问题?

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: [email protected] /cdn-cgi/l/email-protection
npm ERR! Found: @angular/[email protected] /cdn-cgi/l/email-protection
npm ERR! node_modules/@angular/common
npm ERR!   @angular/common@"^14.2.4" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/common@"^15.0.0 || ^16.0.0" from @angular/[email protected] /cdn-cgi/l/email-protection
npm ERR! node_modules/@angular/cdk
npm ERR!   @angular/cdk@"^15.0.0" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

我的结果:

Angular CLI: 14.2.10
Node: 16.10.0
Package Manager: npm 7.24.0 
OS: darwin x64

Angular: 14.2.12
... animations, common, compiler, compiler-cli, core, forms
... localize, platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1402.10
@angular-devkit/build-angular   14.2.10
@angular-devkit/core            14.2.10
@angular-devkit/schematics      14.2.10
@angular/cdk                    15.0.1
@angular/cli                    14.2.10
@angular/material               15.0.1
@schematics/angular             14.2.10
rxjs                            6.6.7
typescript                      4.7.4

我运行后也出现同样的错误ng update @angular/core@14 @angular/cl1@14。其他一些软件包已更新为v15.04 in my pacakge.json。我猜这些都是我应该链接到的依赖项ng update命令让它们全部均匀更新到 v14。解决方案是将 v15 中的所有软件包的版本降级到 v14-lst。

我认为因为我的@angular/compiler and @angular/compiler-cli已更新为v15运行时触发编译错误的原因ng serve

Update:

配置完所有的 linter 后再次遇到这个问题。 我认为除非确实需要,否则您不想检查或检查构建节点模块。拥有打字稿检查节点模块非常重要,特别是如果您不希望不同的包或同一包的不同副本具有冲突的类型声明。 要解决此问题,请在 tsconfig.json 中的编译器选项下添加skipLibCheck: true

tsconfig.json

{
    ...
    complilerOptions: {
        ...
        "skipLibCheck": true
    }
}

这里有关于skipLibCheck的官方文档 https://www.typescriptlang.org/tsconfig#skipLibCheck

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

错误 TS2707 通用类型“ɵɵDirectiveDeclaration”需要 6 到 8 个类型参数 的相关文章

随机推荐