---
id: wiki-2026-0508-type-alias
title: Type Alias (TypeScript)
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [type alias, TS type, Type Aliases]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [typescript, types, language-feature]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
  language: TypeScript
  framework: TypeScript 5.x
---

# Type Alias (TypeScript)

## 매 한 줄
> **"매 `type` keyword 로 매 임의의 type 의 named alias 생성 — interface 와 달리 매 union, intersection, primitive, tuple, conditional 의 모두 표현 가능"**. 매 TypeScript 1.4 (2014) 도입. 매 2026 modern TS 의 type-level programming 의 backbone — 매 string-literal-union, branded type, mapped type, conditional type 의 모두 type alias 의 위에 build.

## 매 핵심

### 매 vs Interface
- **Type alias**: 매 무엇이든 alias (union, primitive, tuple, function). 매 declaration merging 의 X. `&` 로 extend.
- **Interface**: 매 object shape 만. 매 declaration merging 의 O. `extends` 로 extend.
- **2026 권장**: 매 default 의 `type` — 매 더 powerful + composable. Interface 의 매 public API extension point 가 필요한 library 만.

### 매 Type alias 의 능력
- Union: `type Status = 'idle' | 'loading' | 'success'`
- Intersection: `type AB = A & B`
- Primitive alias: `type UserId = string`
- Tuple: `type Point = [number, number]`
- Function: `type Handler = (e: Event) => void`
- Generic: `type Box<T> = { value: T }`
- Conditional: `type NonNull<T> = T extends null ? never : T`
- Mapped: `type Partial<T> = { [K in keyof T]?: T[K] }`
- Template literal: `type Greet = \`hello \${string}\``

### 매 응용
1. Discriminated unions — 매 Redux action, Result type, state machine.
2. Branded types — 매 nominal typing on top of structural.
3. Library type APIs — `Awaited<T>`, `ReturnType<T>`, `Parameters<T>`.

## 💻 패턴

### Discriminated union
```typescript
type Result<T, E = Error> =
  | { ok: true; value: T }
  | { ok: false; error: E };

function parse(s: string): Result<number> {
  const n = Number(s);
  return Number.isNaN(n)
    ? { ok: false, error: new Error('NaN') }
    : { ok: true, value: n };
}

const r = parse('42');
if (r.ok) console.log(r.value); // narrowed to number
else console.error(r.error);
```

### Branded type (nominal)
```typescript
type Brand<T, B> = T & { readonly __brand: B };
type UserId = Brand<string, 'UserId'>;
type PostId = Brand<string, 'PostId'>;

function userId(s: string): UserId { return s as UserId; }
function fetchUser(id: UserId) { /* ... */ }

fetchUser(userId('u_1'));   // OK
// fetchUser('u_1' as PostId); // type error — different brand
```

### Generic + conditional
```typescript
type Awaited<T> = T extends Promise<infer U> ? Awaited<U> : T;

type A = Awaited<Promise<Promise<string>>>; // string
type B = Awaited<number>;                    // number
```

### Mapped type with key remapping
```typescript
type Getters<T> = {
  [K in keyof T as `get${Capitalize<K & string>}`]: () => T[K];
};

type User = { name: string; age: number };
type UserGetters = Getters<User>;
// { getName: () => string; getAge: () => number }
```

### Template literal type
```typescript
type Method = 'GET' | 'POST' | 'PUT' | 'DELETE';
type Endpoint = `/api/${string}`;
type Route = `${Method} ${Endpoint}`;

const r: Route = 'GET /api/users'; // OK
// const bad: Route = 'PATCH /api/x'; // error
```

### Recursive type
```typescript
type Json =
  | string | number | boolean | null
  | Json[]
  | { [k: string]: Json };

const ok: Json = { a: [1, { b: 'x' }] };
```

### Type alias vs interface — practical
```typescript
// type — union OK
type Shape = Circle | Square;

// interface — union NOT OK
// interface Shape = Circle | Square; // syntax error

// interface — declaration merge
interface Window { customProp: string; } // augments lib.dom

// type — no merge
type Window2 = { a: string };
// type Window2 = { b: string }; // error: duplicate
```

## 매 결정 기준
| 상황 | type | interface |
|---|---|---|
| Object shape (단순) | OK | OK |
| Union / primitive / tuple | type only | impossible |
| Library extension point (declaration merge 필요) | impossible | interface only |
| Mapped / conditional / template literal | type only | impossible |
| `extends` chain w/ class implements | OK | OK (slightly idiomatic) |
| 2026 default | **type** | only when needed |

**기본값**: `type` 매 우선 — 매 더 expressive. Interface 의 매 declaration merge 가 필요한 specific case 만.

## 🔗 Graph
- 부모: [[TypeScript]] · [[TypeScript 타입 시스템 (TypeScript Type System)|Type System]]
- 변형: [[Branded-Types]] · [[Discriminated Union]]
- 응용: [[Mapped Types]] · [[Conditional Types]]
- Adjacent: [[Utility Types]]

## 🤖 LLM 활용
**언제**: 매 union/discriminated union design, 매 generic helper type 작성, 매 branded type 으로 nominal typing 도입, 매 mapped/conditional type 으로 derived API type 생성.
**언제 X**: 매 단순 object shape 의 declaration merging 이 필요한 library augmentation (interface 우선).

## ❌ 안티패턴
- **`any` alias**: `type Anything = any` — 매 type system 의 의미 상실.
- **Over-aliasing primitives without brand**: `type Email = string` — 매 nominal protection 의 X (다른 string 와 호환). 매 brand 추가 필수.
- **Deep recursive without bound**: 매 TS 5.x recursion limit (~50) hit — 매 tail-recursion 으로 reframe.
- **Type vs interface flip-flop**: 매 codebase 의 일관성 의 X — 매 lint rule (`@typescript-eslint/consistent-type-definitions`) 으로 enforce.

## 🧪 검증 / 중복
- Verified (TypeScript handbook 공식, TS 5.x release notes).
- 신뢰도 A.

## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — full type alias guide with 7 patterns and type-vs-interface matrix |
