错误:node_modules/@angular/material/core/common-behaviors/constructor.d.ts:14:64 - 错误 TS1005:';'预期的

Posted

技术标签:

【中文标题】错误:node_modules/@angular/material/core/common-behaviors/constructor.d.ts:14:64 - 错误 TS1005:\';\'预期的【英文标题】:Error: node_modules/@angular/material/core/common-behaviors/constructor.d.ts:14:64 - error TS1005: ';' expected错误:node_modules/@angular/material/core/common-behaviors/constructor.d.ts:14:64 - 错误 TS1005:';'预期的 【发布时间】:2021-08-13 22:57:09 【问题描述】:

在我卸载 bootstrap 并安装 angular material 之前,我的应用程序运行良好......然后尝试执行 ng serve 但出现此错误..

Error: node_modules/@angular/material/core/common-behaviors/constructor.d.ts:14:64 - error TS1005: ';' expected.

14 导出声明类型 AbstractConstructor = abstract new (...args: any[]) => T; ~~~ node_modules/@angular/material/core/common-behaviors/constructor.d.ts:14:69 - 错误 TS1109:预期表达式。

14 导出声明类型 AbstractConstructor = abstract new (...args: any[]) => T; ~~~ node_modules/@angular/material/core/common-behaviors/constructor.d.ts:14:82 - 错误 TS1011:元素访问表达式应该带一个参数。

14 export declare type AbstractConstructor = abstract new (...args: any[]) => T;

node_modules/@angular/material/core/common-behaviors/constructor.d.ts:14:83 - 错误 TS1005: ';'预计。

14 导出声明类型 AbstractConstructor = abstract new (...args: any[]) => T; ~ node_modules/@angular/material/core/common-behaviors/constructor.d.ts:14:85[0m - 错误 TS1128:需要声明或声明。

14 导出声明类型 AbstractConstructor = abstract new (...args: any[]) => T; ~~

** Angular Live Development Server 正在监听 localhost:4200,在 http://localhost:4200/ 上打开浏览器 **

✔ 浏览器应用程序包生成完成。

初始块文件 |姓名 |尺寸 样式.css,样式.js |款式 | 427.71 KB

4 个未更改的块

构建于:2021-05-25T16:53:03.977Z - 哈希:55aee97af2b18f6d0a38 - 时间:523ms

错误:node_modules/@angular/material/core/common-behaviors/constructor.d.ts:14:64 - 错误 TS1005: ';'预计。

14 导出声明类型 AbstractConstructor = abstract new (...args: any[]) => T; ~~~ node_modules/@angular/material/core/common-behaviors/constructor.d.ts:14:69 - 错误 TS1109:预期表达式。

14 导出声明类型 AbstractConstructor = abstract new (...args: any[]) => T; ~~~ node_modules/@angular/material/core/common-behaviors/constructor.d.ts:14:82 - 错误 TS1011:元素访问表达式应该带一个参数。

14 export declare type AbstractConstructor = abstract new (...args: any[]) => T;

node_modules/@angular/material/core/common-behaviors/constructor.d.ts:14:83 - 错误 TS1005: ';'预计。

14 导出声明类型 AbstractConstructor = abstract new (...args: any[]) => T; ~ node_modules/@angular/material/core/common-behaviors/constructor.d.ts:14:85[0m - 错误 TS1128:需要声明或声明。

14 导出声明类型 AbstractConstructor = abstract new (...args: any[]) => T; ~~

Error: node_modules/@angular/material/core/common-behaviors/constructor.d.ts:14:55 - error TS2304: Cannot find name 'abstract'.

14 export declare type AbstractConstructor<T = object> = abstract new (...args: any[]) => T;
                                                         ~~~~~~~~
node_modules/@angular/material/core/common-behaviors/constructor.d.ts:14:78 - error TS2693: 'any' only refers to a type, but is being used as a value here.

14 export declare type AbstractConstructor<T = object> = abstract new (...args: any[]) => T;
                                                                                ~~~
node_modules/@angular/material/core/common-behaviors/constructor.d.ts:14:88 - error TS2304: Cannot find name 'T'.

14 export declare type AbstractConstructor<T = object> = abstract new (...args: any[]) => T;
                                                                                          ~
node_modules/@angular/material/core/option/optgroup.d.ts:17:22 - error TS2420: Class '_MatOptgroupBase' incorrectly implements interface 'CanDisable'.
  Property 'disabled' is missing in type '_MatOptgroupBase' but required in type 'CanDisable'.

17 export declare class _MatOptgroupBase extends _MatOptgroupMixinBase implements CanDisable 
                        ~~~~~~~~~~~~~~~~

  node_modules/@angular/material/core/common-behaviors/disabled.d.ts:12:5
    12     disabled: boolean;
           ~~~~~~~~
    'disabled' is declared here.
node_modules/@angular/material/form-field/form-field.d.ts:64:22 - error TS2420: Class 'MatFormField' incorrectly implements interface 'CanColor'.
  Type 'MatFormField' is missing the following properties from type 'CanColor': color, defaultColor

64 export declare class MatFormField extends _MatFormFieldMixinBase implements AfterContentInit, AfterContentChecked, AfterViewInit, OnDestroy, CanColor 
                        ~~~~~~~~~~~~
node_modules/@angular/material/input/input.d.ts:30:22 - error TS2420: Class 'MatInput' incorrectly implements interface 'CanUpdateErrorState'.
  Type 'MatInput' is missing the following properties from type 'CanUpdateErrorState': updateErrorState, errorState

30 export declare class MatInput extends _MatInputMixinBase implements MatFormFieldControl<any>, OnChanges, OnDestroy, AfterViewInit, DoCheck, CanUpdateErrorState 
                        ~~~~~~~~
node_modules/@angular/material/input/input.d.ts:30:22 - error TS2720: Class 'MatInput' incorrectly implements class 'MatFormFieldControl<any>'. Did you mean to extend 'MatFormFieldControl<any>' and inherit its members as a subclass?
  Property 'errorState' is missing in type 'MatInput' but required in type 'MatFormFieldControl<any>'.

30 export declare class MatInput extends _MatInputMixinBase implements MatFormFieldControl<any>, OnChanges, OnDestroy, AfterViewInit, DoCheck, CanUpdateErrorState 
                        ~~~~~~~~

  node_modules/@angular/material/form-field/form-field-control.d.ts:37:14
    37     readonly errorState: boolean;
                    ~~~~~~~~~~
    'errorState' is declared here.
node_modules/@angular/material/button/button.d.ts:22:22 - error TS2420: Class 'MatButton' incorrectly implements interface 'CanColor'.
  Type 'MatButton' is missing the following properties from type 'CanColor': color, defaultColor

22 export declare class MatButton extends _MatButtonMixinBase implements AfterViewInit, OnDestroy, CanDisable, CanColor, CanDisableRipple, FocusableOption 
                        ~~~~~~~~~
node_modules/@angular/material/button/button.d.ts:22:22 - error TS2420: Class 'MatButton' incorrectly implements interface 'CanDisable'.
  Property 'disabled' is missing in type 'MatButton' but required in type 'CanDisable'.

22 export declare class MatButton extends _MatButtonMixinBase implements AfterViewInit, OnDestroy, CanDisable, CanColor, CanDisableRipple, FocusableOption 
                        ~~~~~~~~~

  node_modules/@angular/material/core/common-behaviors/disabled.d.ts:12:5
    12     disabled: boolean;
           ~~~~~~~~
    'disabled' is declared here.
node_modules/@angular/material/button/button.d.ts:22:22 - error TS2420: Class 'MatButton' incorrectly implements interface 'CanDisableRipple'.
  Property 'disableRipple' is missing in type 'MatButton' but required in type 'CanDisableRipple'.

22 export declare class MatButton extends _MatButtonMixinBase implements AfterViewInit, OnDestroy, CanDisable, CanColor, CanDisableRipple, FocusableOption 
                        ~~~~~~~~~

  node_modules/@angular/material/core/common-behaviors/disable-ripple.d.ts:12:5
    12     disableRipple: boolean;
           ~~~~~~~~~~~~~
    'disableRipple' is declared here.
node_modules/@angular/material/toolbar/toolbar.d.tsm:22:22 - error TS2420: Class 'MatToolbar' incorrectly implements interface 'CanColor'.
  Type 'MatToolbar' is missing the following properties from type 'CanColor': color, defaultColor

22 export declare class MatToolbar extends _MatToolbarMixinBase implements CanColor, AfterViewInit 
                        ~~~~~~~~~~
node_modules/@angular/material/progress-spinner/progress-spinner.d.ts:40:22 - error TS2420: Class 'MatProgressSpinner' incorrectly implements interface 'CanColor'.
  Type 'MatProgressSpinner' is missing the following properties from type 'CanColor': color, defaultColor

40 export declare class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements OnInit, CanColor 
                        ~~~~~~~~~~~~~~~~~~

【问题讨论】:

【参考方案1】:

使用以下版本的 Angular Material npm i @angular/material@11.2.13 解决了这个问题

【讨论】:

谢谢,是的,我的角度版本是 11,材料版本是 12,这就是我出错的原因......节省了我的一天。【参考方案2】:

当我在 Stackblitz 上使用角度材料时,我遇到了类似的问题。经过一番研究,我发现这是由于 AngularAngular Material 的版本不匹配造成的。

要解决此问题,请将所有依赖项更新到最新版本,或者选择与您的 Angular 版本兼容的 @angular/material

附言

    我的 Angular 版本是 11,我使用的是 Angular Material 12。

    如果您收到以下错误Error in turbo_modules/@angular/material@12.0.3/table/table-module.d.ts (8:22),请禁用 Ivy。有关详细信息,请参阅此问题:How to fix Stackblitz ngcc error with Material Design MatTableModule?

【讨论】:

【参考方案3】:

这很可能是由于本地项目安装的 TypeScript 版本与 @angular/material 所需的 TypeScript 版本不匹配。在 package.json 中检查您使用的是哪个 TypeScript 版本,并查看 @angular/material 需要哪个 TypeScript 版本。

如果您的本地 TypeScript 版本落后,您很可能不得不降级 @angular/material 的版本。

【讨论】:

【参考方案4】:

面临同样的问题。 angular/material 版本是 12,angular 是 11。将 angular/material 降级到 11 并开始工作。

【讨论】:

【参考方案5】:

对我来说,这是 package.json 和 VS TypeScript 扩展中的 TypeScript 版本不匹配。

package.json - 4.3.5

项目 -> 属性 -> TypeScript 构建 - 4.1

然后我去VS菜单:扩展->管理扩展->搜索并安装版本为package.json文件并重启VS。

问题解决了;)

【讨论】:

以上是关于错误:node_modules/@angular/material/core/common-behaviors/constructor.d.ts:14:64 - 错误 TS1005:';'预期的的主要内容,如果未能解决你的问题,请参考以下文章

angular中安装@angular/cdk时遇到的错误——node_modules/@angular/cdk/table/table.d.ts:277:9 - error TS1086: An ac

node_modules/@angular/material/table/cell.d.ts 中的错误 -Typescript 版本问题 angular

node_modules/@angular/fire/firebase.app.module.d.ts 中的错误?

angular中安装@angular/cdk时遇到的错误——node_modules/@angular/cdk/table/table.d.ts:277:9 - error TS1086: An ac

angular中安装@angular/cdk时遇到的错误——node_modules/@angular/cdk/table/table.d.ts:277:9 - error TS1086: An ac

angular中安装@angular/cdk时遇到的错误——node_modules/@angular/cdk/table/table.d.ts:277:9 - error TS1086: An ac