HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
🧐
Sonny
/
✅
data!의 !는 undefined가 아니라는 타입 단언
✅

data!의 !는 undefined가 아니라는 타입 단언

날짜
Jul 5, 2022
function checkSupportMethod(supportMethod: string[], method?: string) { if (supportMethod.indexOf(method!) === -1) { throw new BadRequestError('지원하지 않는 Method!'); } }
  • method!는 method가 undefined가 아니라는 타입 단언이다!
function checkSupportMethod(supportMethod: string[], method?: string) { if (!method) { return } if (supportMethod.indexOf(method) === -1) { throw new BadRequestError('지원하지 않는 Method!'); } }
  • 타입단언은 좋지 않으니.. 위와 같이 변경 가능!