当该值在所使用的接口之一中明显可用时,为什么IDE会给出此错误? 上下文操作的接口使用两个接口来指定调度操作中的一种数据类型.当我try 更新Reducer中的数据时,IDE显示此错误.
Property 'firstName' does not exist on type 'iCards | iSearch'. Property 'firstName' does not exist on type 'iCards'.个
下面是上下文操作的接口以及用于创建它的接口.
interface iAction{
type: 'search' | 'show all';
payload: iSearch | iCards
}
interface iSearch {
firstName: string;
lastName: string;
country: string;
}
interface iCards {
searchText: string;
searchParams: string[];
}
以下是减速器代码.
export default function CardsReducer(initialData: iInitialData, action: iAction) {
const data = structuredClone(initialData); <-- initialData.firstName is already set to an empty string
data.firstName = action.payload.firstName; <--- IDE gives me the error here.
return data
}
名字在iSearch接口和iInitialData接口中,为什么它告诉我它不存在?