tooling
TypeScript 기초.
타입 시스템, inference, interface vs type, tsconfig, 프론트엔드 활용.
TypeScript는 JavaScript에 정적 타입을 더해, compile time에 오류를 잡고 IDE 자동완성을 강화합니다.
📘 핵심 개념
- 기본型:
string,number,boolean,null,undefined - 복합:
Array<T>,Record<K,V>, unionA | B, intersectionA & B - interface는 확장(merge), type은 union/utility에 유리
- Generics:
function id<T>(x: T): T - Utility:
Partial,Pick,Omit,ReturnType
🧠 inference
const user = { name: 'mason', age: 30 }; // inferred
type User = typeof user;
function fetchUser(id: string) {
return { id, name: 'mason' };
}
type FetchResult = ReturnType<typeof fetchUser>;
- literal type 고정
- context에서 타입 추론 최대한 활용, explicit은 API boundary
⚙️ tsconfig (자주 쓰는)
| 옵션 | 의미 |
|---|---|
strict | strictNullChecks 등 일괄 |
moduleResolution | bundler, node16 |
jsx | react-jsx |
paths | alias (@/*) |
noEmit | type check only (Vite/Next) |
💻 프론트엔드
- React:
FC보다 props interface 직접 - API response: Zod/io-ts runtime validate + infer type
any최소 — unknown + narrowing- Next.js, Emotion —
@types/*
🔗 참고 자료
- TypeScript Docs — TypeScript 공식 문서 홈이다.
- Handbook — 타입 시스템의 핵심 개념을 설명한다.
- TSConfig Reference —
strict,moduleResolution등 옵션을 설명한다.
