로딩
요청 처리 중입니다...

[개발 지식] 타입스크립트 컴파일 타임과 런타임의 차이

 [개발 지식] 타입스크립트 컴파일 타임과 런타임의 차이

// 1. 런타임 값에 의존하는 타입 예시 const fruits = ['apple', 'banana', 'orange'] as const; type Fruit = typeof fruits[number]; // 'apple' | 'banana' | 'orange' // 런타임에서 값이 변경되면 타입이 업데이트되지 않음 fruits.push('grape'); // 런타임에서 값이 변경됨 // 하지만 타입스크립트는 여전히 'apple' | 'banana' | 'orange'로 인식 // 2.

런타임 값에 의존하지 않는 타입 예시 type Fruit = 'apple' | 'banana' | 'orange' | 'grape'; const fruits: Fruit[] = ['apple', 'banana', 'orange']; // 런타임에서 값이 변경되어도 타입은 안정적 fruits.push('grape'); // 타입 체크가 안정적 // 3. 컴파일 타임 vs 런타임 예시 // 컴파일 타임...