티스토리 뷰

에러 내용❗

  • Typescript 에러.
  • string이나 undefined은 string 타입을 할당할 수 없다는 오류였다.
  • Kakao javascript key를 .env에 넣어서 사용하려고 하는데 오류가 발생하였다.
<KaKaoBtn
  jsKey={process.env.REACT_APP_KAKAO_KEY} // Error Point!
  buttonText='카카오 계정으로 로그인'
  onSuccess={this.responseKaKao}
  onFailure={this.responseFail}  
  getProfile={true}
/>

exclamation mark(Nullable)를 사용하여 Error를 피할 수 있다.

<KaKaoBtn
  jsKey={process.env.REACT_APP_KAKAO_KEY!} // exclamation mark(!)
  buttonText='카카오 계정으로 로그인'
  onSuccess={this.responseKaKao}
  onFailure={this.responseFail}  
  getProfile={true}
/>

Nullable

Nullable은 null과 undefind를 허용한다.



references

Typescript: Type 'string | undefined' is not assignable to type 'string'

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2026/02   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
글 보관함