我有一个Angular应用程序,它构建和运行得很好,但是在添加angular/material时出现了一些奇怪的npm依赖性问题,所以我删除了package-lock.json
和我的node_modules
,npm i
现在安装时不会出错。
但是,我现在在编译时得到一堆TypeScript错误,这是我以前没有的。
我的package.json有以下依赖项:
"dependencies": {
"@angular/animations": "^14.1.0",
"@angular/common": "^14.1.0",
"@angular/compiler": "^14.1.0",
"@angular/core": "^14.1.0",
"@angular/forms": "^14.1.0",
"@angular/material": "14.1.0",
"@angular/material-moment-adapter": "14.1.0",
"@angular/platform-browser": "^14.1.0",
"@angular/platform-browser-dynamic": "^14.1.0",
"@angular/router": "^14.1.0",
"@ngrx/component-store": "^14.3.0",
"@ngrx/effects": "^14.2.0",
"@ngrx/entity": "^14.2.0",
"@ngrx/store": "^14.2.0",
"@ngrx/store-devtools": "^14.2.0",
"@ngx-translate/core": "^14.0.0",
"tslib": "^2.3.0",
"uuid": "^8.3.2",
"zone.js": "~0.11.4"
"devDependencies": {
"@angular-devkit/build-angular": "^14.1.0",
"@angular-eslint/builder": "14.0.2",
"@angular-eslint/eslint-plugin": "14.0.2",
"@angular-eslint/eslint-plugin-template": "14.0.2",
"@angular-eslint/schematics": "14.0.2",
"@angular-eslint/template-parser": "14.0.2",
"@angular/cli": "~14.1.0",
"@angular/compiler-cli": "^14.1.0",
"@types/jasmine": "~4.0.0",
"@types/lodash": "^4.14.184",
"@types/uuid": "^8.3.4",
"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",
"eslint": "^7.32.0",
"jasmine-core": "~4.2.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.0.0",
"typescript": "^4.8.2"
我确实有TypeScript 4. 7,但在得到下面的错误后尝试升级(没有任何区别)。
我现在得到的错误是
Error: node_modules/@angular/material/datepicker/index.d.ts:602:48 - error TS2344: Type 'MatDatepickerControl<unknown>' does not satisfy the constraint 'MatDatepickerControl<{}>'.
The types returned by 'getStartValue()' are incompatible between these types.
Type 'unknown' is not assignable to type '{} | null'.
602 constructor(_datepicker: MatDatepickerBase<MatDatepickerControl<unknown>, unknown>, _viewContainerRef: ViewContainerRef);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error: node_modules/@angular/material/datepicker/index.d.ts:621:48 - error TS2344: Type 'MatDatepickerControl<unknown>' does not satisfy the constraint 'MatDatepickerControl<{}>'.
621 constructor(_datepicker: MatDatepickerBase<MatDatepickerControl<unknown>, unknown>);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error: node_modules/@angular/material/datepicker/index.d.ts:777:36 - error TS2344: Type 'MatDatepickerControl<unknown>' does not satisfy the constraint 'MatDatepickerControl<{}>'.
777 _datepicker: MatDatepickerBase<MatDatepickerControl<unknown>, unknown>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error: node_modules/@angular/material/datepicker/index.d.ts:778:48 - error TS2344: Type 'MatDatepickerControl<unknown>' does not satisfy the constraint 'MatDatepickerControl<{}>'.
778 constructor(_datepicker: MatDatepickerBase<MatDatepickerControl<unknown>, unknown>);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error: node_modules/@ngrx/effects/src/effect_decorator.d.ts:7:84 - error TS2344: Type 'T' does not satisfy the constraint 'Object'.
7 export declare function getEffectDecoratorMetadata<T>(instance: T): EffectMetadata<T>[];
~
node_modules/@ngrx/effects/src/effect_decorator.d.ts:7:52
7 export declare function getEffectDecoratorMetadata<T>(instance: T): EffectMetadata<T>[];
~
This type parameter might need an `extends Object` constraint.
Error: node_modules/@ngrx/effects/src/effects_metadata.d.ts:3:75 - error TS2344: Type 'T' does not satisfy the constraint 'Object'.
3 export declare function getSourceMetadata<T>(instance: T): EffectMetadata<T>[];
~
node_modules/@ngrx/effects/src/effects_metadata.d.ts:3:43
3 export declare function getSourceMetadata<T>(instance: T): EffectMetadata<T>[];
~
This type parameter might need an `extends Object` constraint.
Error: node_modules/@ngrx/effects/src/models.d.ts:25:31 - error TS2344: Type 'T' does not satisfy the constraint 'Object'.
25 [key in EffectPropertyKey<T>]?: EffectConfig;
~
node_modules/@ngrx/effects/src/models.d.ts:24:37
24 export declare type EffectsMetadata<T> = {
~
This type parameter might need an `extends Object` constraint.
所以都是从图书馆。我刚刚添加了材料,所以不确定我是否会得到他们之前,但是,我没有这些错误从NgRx图书馆之前
我可以通过添加以下内容来消除这些问题:
"compilerOptions": {
"skipLibCheck": true,
到tsconfig.json
,但请注意,隐藏这些错误是最好的主意。
为什么我突然收到这些?
1条答案
按热度按时间envsm3lx1#
我不知道它是正确的,但对于这个问题
错误:节点模块/@Angular /材料/日期选择器/索引。d.ts:778:48 -错误TS 2344:类型“MatDatepickerControl未知”不满足约束“MatDatepickerControl {}”。
我遇到了同样的问题,我去了node_modules/@angular/material/datepicker/index.d.ts:778:48,并将MatDatepickerControl unknown更改为MatDatepickerControl any。这对我来说很有效,但我只有一个错误,而不是像你一样的所有列表。