Untitled

TS2322: '(checkAuthRequestBody: CheckAuthRequestBody) => Promise<void>' 유형은 'CheckAuth' 유형에 할당할 수 없습니다. 'Promise<void>' 유형은 'Promise<CheckAuthRes>' 유형에 할당할 수 없습니다.

문제코드

export const checkAuth: CheckAuth = async (checkAuthRequestBody) => {
  KStadiumInstance.post<CheckAuthRes>(
    `${SUB_URL}/util/auth/check`,
    checkAuthRequestBody,
  ).then((res) => res.data.data);
};
export interface CheckAuthRequestBody {
  userId: string;
  password: string;
}

export interface CheckAuthRes {
  resultCode: 'success' | 'failed';
  resultMessage: string;
  totalCount: number;
  data: any;
}

export type CheckAuth = (
  checkAuthRequestBody: CheckAuthRequestBody,
) => Promise<CheckAuthRes>;

해결된 코드

export const checkAuth: CheckAuth = async (checkAuthRequestBody) =>
  KStadiumInstance.post<CheckAuthRes>(
    `${SUB_URL}/util/auth/check`,
    checkAuthRequestBody,
  ).then((res) => res.data.data);
export interface CheckAuthRequestBody {
  userId: string;
  password: string;
}

export interface CheckAuthRes {
  resultCode: 'success' | 'failed';
  resultMessage: string;
  totalCount: number;
  data: Record<string, never>;
}

export type CheckAuth = (
  checkAuthRequestBody: CheckAuthRequestBody,
) => Promise<Record<string, never>>;

// Promise<void> 를 시키거나 -> 왜?? 어차피 안 쓸꺼니깐

문제 발생 원인

export const func = (res: CheckAuthRes) => {res: CheckAuthRes} // () => void
export const func2 = (res: CheckAuthRes) => res.data // () => res.data

추가로 알게된 내용

  1. 실제로 data값이 빈객체로 반환되는 경우
export interface CheckAuthRes {
  resultCode: 'success' | 'failed';
  resultMessage: string;
  totalCount: number;
  data: Record<string, never>;  
}

위와 같이 Record<string, never>로 표시할 수도 있지만