error TS2707 Generic type 'ɵɵDirectiveDeclaration' requires between 6 and 8 type arguments
在安装了angular material并在项目的app.module.ts中添加了angular material的导入后,我遇到了错误,所有的解决方案都没有用。我用了angular 14,node 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。接下来我试着重新安装angular material--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: highlight@0.0.0
npm ERR! Found: @angular/common@14.2.12
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/cdk@15.0.0
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.
我的Ng v结果:
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/cli @angular/core --allow-dirty --force
然后,将"~"符号从样式中删除,如果它存在的话。
将@import "~@coreui/coreui-pro/scss/coreui"
改为@import "@coreui/coreui-pro/scss/coreui"
。
这是一个兼容性问题。如果你安装了任何新的软件包,请检查它们的Github和它们的依赖性。
我安装了ng-bootstrap@14,它需要15版本的angular,但我的项目是angular 14,所以我不得不把软件包降级到13来解决这个问题。
我在运行后也有同样的错误,ng update @angular/core@14 @angular/cl1@14
。在我的pacakge.json
中,其他一些软件包被更新为v15.04
。我猜想这些都是我应该用ng update
命令链起来的依赖项,让它们都均匀地更新到v14。解决办法就是把所有在v15的软件包的版本降级到v14-lst。
我想,因为我的@angular/compiler
和@angular/compiler-cli
已经更新到了v15
,所以在运行ng serve
时引发了编译错误。
更新:
在配置了我所有的linters之后又遇到了这个问题。 我认为除非你真的需要,否则你不应该对构建节点模块进行lint或检查。让typescript检查节点模块是很重要的,尤其是当你不希望不同的包或同一个包的不同副本有冲突的类型声明时。 为了解决这个问题,在你的tsconfig.json的编译器选项下添加skipLibCheck: true
tsconfig.json文件
{
...
complilerOptions: {
...
skipLibCheck: true
}
}
如果你使用Angular 14,请使用ngrx/component 14.3.2,。 或者直接更新到Angular 15。
我找到了一个临时的解决方案,我有一个同样的错误,我去了node_modules里面,注释了错误的行。
在我的例子中,它是node_modules/@angular/cdk/bidi/index.d.ts
中的一个评论和node_modules/@angular/cdk/scrolling/index.d.ts
中的几个评论,尽管我不知道是什么原因导致了这个错误,我也不知道注释这几行是否会在将来引起问题,有必要进一步探讨。
我也面临着确切的问题,我只是首先更新了我的NodeJS(从NodeJS官方网站的16到18),后来我还需要将我的angular cli/angular core从14版更新到15版。存储库不干净。请在更新前提交或储存任何更改。我的应用程序又开始正常运行了。
在做完这一切后,我的问题得到了解决,我的应用程序又开始正常工作了。
我也面临着同样的问题。
**error ts2707: generic type 'ɵɵdirectivedeclaration' requires between 6 and 8 type arguments.**
但是,别担心,解决这个问题很简单:-。
你只需将Angular从14版更新到15版即可。
下面的命令是
命令 :-
ng update @angular/cli @angular/core --allow-dirty --force
那么你的应用程序就会像你所期望的那样运行!
祝您好运!