[英]TypeScript error: Void is not assignable to parameter type
I am getting this error in TypeScript: 我在TypeScript中遇到此错误:
Argument type (response: Response<DSBMannschaftDTO[]>) => void is not
assignable to parameter type ((value:Response<DSBMannschaftDTO[]>) =>
(PromiseLike<void> | void)) null | undefined | undefined
This is my schema: 这是我的架构:
export class DsbMannschaftDTO implements DataTransferObject {
id: number;
vereinId: number;
nummer: number;
benutzerId: number;
veranstaltungsId: number;
version: number;
static copyFrom(optional: {
id?: number,
vereinId?: number,
nummer?: number,
benutzerId?: number;
veranstaltungsId: number;
version?: number
} = {}): DsbMannschaftDTO {
const copy = new DsbMannschaftDTO();
copy.id = optional.id || null;
copy.vereinId = optional.vereinId || null;
copy.benutzerId = optional.benutzerId || null;
copy.veranstaltungsId = optional.veranstaltungsId || null;
copy.nummer = optional.nummer || null;
copy.version = optional.version || null;
return copy;
}
}
and this is my code 这是我的代码
private loadTableRows() {
this.loading = true;
this.dsbMannschaftDataProvider.findAll()
.then(onfulfilled:(response: Response<DsbMannschaftDTO[]>) => this.handleLoadTableRowsSuccess(response))
.catch(onrejected:(response: Response<DsbMannschaftDTO[]>) => this.handleLoadTableRowsFailure(response));
}
What exactly does this error mean? 该错误的确切含义是什么? Thank you very much in advance
提前非常感谢你
The problem here is your object definition. 这里的问题是您的对象定义。 You defined
DsbMannschaftDTO
like: 您将
DsbMannschaftDTO
定义DsbMannschaftDTO
:
id: number; <- value has to be a number
vereinId: number; <- value has to be a number
and so on. 等等。 Now you pass the options object with the definition:
现在,您传递带有定义的options对象:
id?: number, <- number or undefined
vereinId?: number, <- number or undefined
this is the first missmatch to number
. 这是第一个
number
匹配。 number | undefined
number | undefined
is not assignable to number
. number | undefined
不可分配给number
。
And then you write: 然后你写:
copy.id = optional.id || null; <- copy.id can now be number or undefined or null.
This is the second missmatch to number
. 这是第二次来missmatch
number
。 number | undefined | null
number | undefined | null
is not assignable to number
. number | undefined | null
不可分配给number
。
To fix this, replace the null with 0
(better to say with a type matching default). 要解决此问题,请将null替换为
0
(最好使用与默认类型匹配的类型)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.