///

TypeScript interface vs type Capsule

interface와 type은 TypeScript에서 대부분 호환되지만, interface는 객체 shape + declaration merging 에 특화, type은 union/intersection/primitive/mapped type 등 모든 type expression 을 이름붙이는 범용 도구. 공식 핸드북 권장: 가능하면 interface, 불가능하면 type.

///

kind: capsule status: active visibility: private license: CC-BY-SA-4.0 summary: interface는 객체/클래스 shape 확장용, type은 union/intersection/primitive 포함 범용. 실무 권장: public API는 interface, 내부 유틸은 type. tags: - typescript - type-system - interface - type-alias - capsule


TypeScript interface vs type Capsule

Summary#

interfacetype은 TypeScript에서 대부분 호환되지만, interface객체 shape + declaration merging에 특화, typeunion/intersection/primitive/mapped type모든 type expression을 이름붙이는 범용 도구. 공식 핸드북 권장: 가능하면 interface, 불가능하면 type.

Claim#

interface만 되는 것#

  • Declaration merging: 같은 이름 interface 두 번 선언 시 자동 병합 — 라이브러리 augmentation에 필수 typescript interface Window { myCustom?: string; } // lib.dom에 주입
  • class의 implements 대상 — 가장 일반적

type만 되는 것#

  • Union / Intersection / Primitive alias typescript type ID = string | number; type Direction = "up" | "down" | "left" | "right"; type UserOrAdmin = User & { role: "admin" };
  • Mapped / Conditional / Template literal types typescript type Readonly<T> = { readonly [K in keyof T]: T[K] }; type NonNull<T> = T extends null | undefined ? never : T; type CSSVar = `--${string}`;
  • tuple alias: type Pair = [string, number]

공통#

  • extends: interface는 interface B extends A, type은 type B = A & {...}
  • 객체 shape 표현은 둘 다 가능, 성능 차이 거의 없음

Scope#

  • TypeScript 2.0+ (type은 2.0에 도입, template literal은 4.1+)
  • 라이브러리 작성자: public API interface, 내부 type — merge 확장성 때문

Caveats#

  • interface declaration merging은 의도치 않은 전역 오염 위험 — global scope 노출 시 신중
  • type으로 만든 객체 타입은 extends 체인에서 약간 다른 추론 보일 수 있음 (실무에 영향 거의 없음)
  • 동일 이름 type alias 재정의 시 에러, interface는 병합 — 의도 명확히 하고 선택

Source#

  • Q: https://stackoverflow.com/q/37233735
  • A: https://stackoverflow.com/a/37233777 — by Binary Birch Tree
  • License: CC BY-SA 4.0 (Stack Exchange)
  • last_edit: 2024
  • 조회일: 2026-04-19

Sagwan Revalidation 2026-04-19T01:49:59Z#

  • verdict: ok
  • note: TypeScript 5.x 기준으로도 interface/type 핵심 차이와 권장 패턴은 여전히 유효하며 오탈자·모순 없음.