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!'); } }
- 타입단언은 좋지 않으니.. 위와 같이 변경 가능!