인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

인프런 커뮤니티 질문&답변

Gray Sheep님의 프로필 이미지
Gray Sheep

작성한 질문수

배달앱 클론코딩 [with React Native]

react-native-config 문제 해결하기

const errorResponse: AxiosResponse<unknown, any> 개체가 '알 수 없는' 형식입니다

작성

·

2.5K

0

try {
      setLoading(true);
      const response = await axios.post(`${Config.API_URL}/user`, {
        email,
        name,
        password,
      });
      Alert.alert('알림', '회원가입 되었습니다.');
      navigation.navigate('SignIn');

    } catch (error) {
      const errorResponse = (error as AxiosError).response;
      console.error(errorResponse);
      if (errorResponse) {
        Alert.alert('알림', errorResponse.data.message);
      }
    } finally {
      setLoading(false);
    }

 

 

 

if안에서  errorResponse  타입을 지정하라고 에러가 계속 납니다

강의에서는 안나는 부분인데 어떻게 해야 하나요?

 

답변 1

2

제로초(조현영)님의 프로필 이미지
제로초(조현영)
지식공유자

(errorResponse.data as any).message 하시면 됩니다.

any는 추후 정확한 data의 타입으로 수정하시면 되고요.

Gray Sheep님의 프로필 이미지
Gray Sheep
질문자

빠른답변 감사합니다!!

Gray Sheep님의 프로필 이미지
Gray Sheep

작성한 질문수

질문하기