在 ng 服务上出错:类型 'null' 不可分配给类型 'string | Dayjs'



我正在进行一个Angular项目。我正在尝试使用ngx日期范围选择器材料。我安装了以下软件包:

npm安装ngx日期范围选择器材料--保存

npm install dayjs--保存

我添加了根据ngx日期范围选择器材料显示的示例代码。

我的component.ts和component.html有以下代码:

ranges: any = {
'Today': [dayjs(), dayjs()],
'Yesterday': [dayjs().subtract(1, 'days'), dayjs().subtract(1, 'days')],
'Last 7 Days': [dayjs().subtract(6, 'days'), dayjs()],
'Last 30 Days': [dayjs().subtract(29, 'days'), dayjs()],
'This Month': [dayjs().startOf('month'), dayjs().endOf('month')],
'Last Month': [dayjs().subtract(1, 'month').startOf('month'), dayjs().subtract(1, 'month').endOf('month')]
}
model: any;
<input type="text" ngxDaterangepickerMd startKey="start" endKey="end" [ranges]="ranges" [(ngModel)]="model">

当我运行ng-serve时,我得到了以下错误:


Error: node_modules/ngx-daterangepicker-material/daterangepicker.component.d.ts:173:9 - error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type
Type 'null' is not assignable to type 'string | Dayjs'.
173     get minDate(): dayjs.Dayjs | null;
~~~~~~~

Error: node_modules/ngx-daterangepicker-material/daterangepicker.component.d.ts:179:9 - error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type
179     get maxDate(): dayjs.Dayjs | null;
~~~~~~~

根据上面的错误,它似乎不是从我的代码。它指向node_modules文件夹下的代码。

以下是package.json 的版本

"dayjs":"1.11.5〃;,

"ngx日期范围选择器材料":"6.0.2〃;,

有人能帮助解决此错误吗?

根据您对No provider for LocaleService!的评论。

您应该配置必要的提供程序,如下所示

import { LocaleService } from './locale.service';
.
.
.
.

{ provide: LocaleService, useClass: LocaleService, deps: [LOCALE_CONFIG] },

有关更多信息,请单击此处

根据@NarenMurali在评论中的建议,在tsconfig.json文件的compilerOptions下添加"skipLibCheck": true解决了这个问题。

附言:我还面临着另一个获得NullInjectorError的问题。这是因为我的模块层次结构。在AppModule下添加NgxDaterangepickerMd.forRoot()后,该错误得到了解决。

相关内容

最新更新