[英]Argument of type 'X' is not assignable to parameter of type 'Y'
I have created those types:我创建了这些类型:
export type Optional<T> = T | null;
and I have this function我有这个功能
updateBook( book: Array<Optional<Hostel>>)
that I call with我打电话给
let book: Hostel | null [] = [null];
updateBook(book)
but I have this error但我有这个错误
- error TS2345: Argument of type 'Hostel | null[]' is not assignable to parameter of type 'Optional<Hostel>[]
Hostel | null []
Hostel | null []
means a union between Hostel
and null[]
. Hostel | null []
表示Hostel
和null[]
之间的联合。 The []
has a higher precedence than the union operator ( |
). []
的优先级高于联合运算符 ( |
)。
You probably wanted to say an array of Hostel | null
你可能想说的是一系列Hostel | null
Hostel | null
which can be written as (Hostel | null)[]
or, more readably IMO Array<Hostel | null>
Hostel | null
可以写为(Hostel | null)[]
或更易读的 IMO Array<Hostel | null>
Array<Hostel | null>
. Array<Hostel | null>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.