mason
mason-log.

mason

mason.

안녕하세요. mason 입니다.

tooling

TypeScript 기초.

타입 시스템, inference, interface vs type, tsconfig, 프론트엔드 활용.

TypeScript는 JavaScript에 정적 타입을 더해, compile time에 오류를 잡고 IDE 자동완성을 강화합니다.

📘 핵심 개념

  • 기본型: string, number, boolean, null, undefined
  • 복합: Array<T>, Record<K,V>, union A | B, intersection A & 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 (자주 쓰는)

옵션의미
strictstrictNullChecks 등 일괄
moduleResolutionbundler, node16
jsxreact-jsx
pathsalias (@/*)
noEmittype check only (Vite/Next)

💻 프론트엔드

  • React: FC보다 props interface 직접
  • API response: Zod/io-ts runtime validate + infer type
  • any 최소 — unknown + narrowing
  • Next.js, Emotion — @types/*

🔗 참고 자료