
1. Dynamic Types 혼란
JavaScript
let id = "haechilim"; id = 1234; id.slice(2); //Errorfunction sum(a, b) { return a + b; } sum("x", "y") //xyTypeScript
let id: string = "haechilim"; id = 1234; //Error id.slice(2);function sum(a: number, b: number): number { return a + b; } sum("x", "y") //Error개발 도구(IDE나 컴파일러 등)로 부터 잘못된 변수/함수 사용에 대한 에러 알림
2. 알기 힘든 객체구조
JavaScript
const user = getUserById("haechilim"); console.log(user.name);TypeScript
type User = { id: string, name: string, age: number, male: boolean } const user: User = getUserById("haechilim");API를 구현하고 사용함에 있어 해당 API의 인풋과 아웃풋이 무엇인지 명확하게 표현
코드 작성 시 매번 타입을 결정해야 하기 때문에 번거롭고 코드량이 증가하며 컴파일 시간이 오래 걸림