상황
데이터 객체의 타입을 만들어 사용하던 중 다른 컴포넌트에서 객체 속성이 추가적으로 필요한 경우 어떻게 타입을 사용해야 할까??
export type SDeal = {
id: number;
title: string;
imgURL: string;
price: number;
location: string;
likesCount: number;
}
export type SNewDeal = {
id: number;
title: string;
imgURL: string;
price: number;
location: string;
likesCount: number;
seller: {
avatarImgURL: string;
email: string;
};
createdAt: number;
content: string;
viewsCount: number;
}
export type SDeal = {
id: number;
title: string;
imgURL: string;
price: number;
location: string;
likesCount: number;
seller?: {
avatarImgURL: string;
email: string;
};
createdAt?: number;
content?: string;
viewsCount?: number;
}
undefined | type값
으로 사용할 수 밖에 없다.export type SDeal<IsDetail extends boolean = false> = {
id: number;
title: string;
imgURL: string;
price: number;
location: string;
likesCount: number;
} & (IsDetail extends true ? {
seller: {
avatarImgURL: string;
email: string;
};
createdAt: number;
content: string;
viewsCount: number;
} : {});
env 타입 오류
//tsconfig.json
{
"compilerOptions":{
"types": ["node", "vite/client"],
}
}
invalidateQueries 타입 오류
const { mutate } = useMutation({
onSettled: () => {
queryClient.invalidateQueries({ queryKey: ['reviewList', dataCd] });
}
});