【发布时间】:2021-08-19 17:09:24
【问题描述】:
我有以下 Angular 服务
import { Injectable } from '@angular/core'
import { DictUnit } from '@activejs/core'
@Injectable({
providedIn: 'root',
})
export class RegistrationState {
private _dictionaryUnit = new DictUnit({
id: 'registration',
immutable: true,
persistent: true,
cacheSize: 200,
// initialValue: {},
distinctDispatchCheck: true,
})
get dictUnit() {
return this._dictionaryUnit
}
}
我将服务注入到我的组件中:
export class AgeComponent {
age: IAge = new Age()
constructor(private regState: RegistrationState) {
}
onDobValueChanged(e: any) {
const dob = dayjs(e.value).toDate()
const years = dayjs().diff(dob, 'year')
// TS2345: Argument of type 'string' is not assignable to parameter of type 'never' - ERROR REFERES TO 'age' param
this.regState.dictUnit.set('age', this.age)
}
onDodValueChanged(e: any) {
this.age.dod = dayjs(e.value).toDate()
console.log({ dod: this.age.dod })
}
}
set函数的API在https://api.activejs.dev/classes/dictunit.html#set
为什么我会得到这个结果?
我正在使用以下 #1 "typescript": "~4.1.5" - 严格模式 #2 "@angular/cli": "^11.2.12", #3 Linux Mint Ulyana
谢谢
【问题讨论】:
标签: angular typescript typescript-generics