docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를 Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류. - 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로 자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거, 동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거. - 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming, Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business, Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로, 나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는 title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백). 원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지. - 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서. - 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는 지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지. - Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경. - 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
---
|
||||
id: wiki-2026-0508-ts-brand
|
||||
title: ts-brand
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [ts-brand library, Branded Types library, Nominal Typing TS]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [typescript, branded-types, nominal-typing, library, type-safety]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: typescript
|
||||
framework: ts-brand
|
||||
---
|
||||
|
||||
# ts-brand
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 zero-runtime-cost 의 nominal typing 의 TypeScript"**. ts-brand 는 매 structural typing 의 default 의 TypeScript 에 매 nominal-style brand 의 추가 → 매 UserId 와 매 OrderId 가 매 둘 다 string 이지만 매 swap 의 compile error. 매 2026 의 standard pattern — 매 Effect-TS, Zod, neverthrow 의 모두 의 leverage.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 problem (structural typing 의 limitation)
|
||||
- 매 TypeScript: 매 type UserId = string; type OrderId = string → 매 둘 다 동일 의 interchangeable.
|
||||
- 매 logical bug: 매 fn(userId: UserId) 의 orderId 의 pass 가 의 silent.
|
||||
|
||||
### 매 solution (Brand)
|
||||
- 매 phantom type tag 의 use → 매 compile-time discrimination.
|
||||
- 매 runtime cost = 0 (type-only).
|
||||
|
||||
### 매 ts-brand API
|
||||
- `Brand<Base, Tag>`: 매 branded type 의 create.
|
||||
- `make<T>()`: 매 cast helper.
|
||||
- 매 alternatives: 매 own-rolling, Effect-TS Brand, type-fest Opaque.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### 1. Basic Brand
|
||||
```typescript
|
||||
import { Brand, make } from 'ts-brand';
|
||||
|
||||
type UserId = Brand<string, 'UserId'>;
|
||||
type OrderId = Brand<string, 'OrderId'>;
|
||||
|
||||
const UserId = make<UserId>();
|
||||
const OrderId = make<OrderId>();
|
||||
|
||||
const u: UserId = UserId('u-123');
|
||||
const o: OrderId = OrderId('o-456');
|
||||
|
||||
function fetchUser(id: UserId) { /* ... */ }
|
||||
fetchUser(u); // ✓
|
||||
fetchUser(o); // ✗ Type error
|
||||
fetchUser('raw'); // ✗ Type error
|
||||
```
|
||||
|
||||
### 2. Validated Brand (with runtime check)
|
||||
```typescript
|
||||
type Email = Brand<string, 'Email'>;
|
||||
|
||||
function parseEmail(s: string): Email {
|
||||
if (!/^[^@]+@[^@]+\.[^@]+$/.test(s)) throw new Error(`invalid email: ${s}`);
|
||||
return s as Email;
|
||||
}
|
||||
|
||||
// 매 user 의 input 의 parseEmail 의 통과 만 의 Email 의 acquire.
|
||||
const e = parseEmail(req.body.email);
|
||||
```
|
||||
|
||||
### 3. Brand + Zod (parse 시 brand)
|
||||
```typescript
|
||||
import { z } from 'zod';
|
||||
import type { Brand } from 'ts-brand';
|
||||
|
||||
type UserId = Brand<string, 'UserId'>;
|
||||
const UserIdSchema = z.string().uuid().brand<'UserId'>();
|
||||
// ^? z.ZodBranded<z.ZodString, 'UserId'>
|
||||
|
||||
const id = UserIdSchema.parse('xxx-uuid'); // type: string & z.BRAND<'UserId'>
|
||||
// 매 Zod-native brand 의 ts-brand 와 의 compatible.
|
||||
```
|
||||
|
||||
### 4. Brand removal (rare, escape hatch)
|
||||
```typescript
|
||||
function brandOf<T extends Brand<any, any>>(b: T): UnwrapBrand<T> {
|
||||
return b as any;
|
||||
}
|
||||
type UnwrapBrand<T> = T extends Brand<infer U, any> ? U : never;
|
||||
|
||||
const raw: string = brandOf(u); // 매 e.g., logging
|
||||
```
|
||||
|
||||
### 5. Multi-brand (intersection)
|
||||
```typescript
|
||||
type NonEmpty = Brand<string, 'NonEmpty'>;
|
||||
type Trimmed = Brand<string, 'Trimmed'>;
|
||||
type Clean = NonEmpty & Trimmed;
|
||||
|
||||
function clean(s: string): Clean {
|
||||
const t = s.trim();
|
||||
if (!t) throw new Error('empty');
|
||||
return t as Clean;
|
||||
}
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| 매 ID type (UserId, OrderId) | brand 의 always |
|
||||
| 매 validated string (Email, URL) | brand + parse function |
|
||||
| 매 unit type (Meters, Seconds) | brand 의 use |
|
||||
| 매 throwaway local | 매 brand 의 skip |
|
||||
| 매 Zod ecosystem | z.brand<T>() 의 native 의 prefer |
|
||||
|
||||
**기본값**: 매 domain 의 distinct identity 의 string/number type → 매 brand 의 use.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[TypeScript]] · [[Nominal-Typing-in-TypeScript|Nominal Typing]]
|
||||
- 변형: [[Branded Types]] · [[Opaque Types (TypeScript)]]
|
||||
- 응용: [[Zod]] · [[Effect TS]] · [[Type Safety]]
|
||||
- Adjacent: [[Structural Typing]] · [[Runtime Validation]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: TypeScript domain modeling, ID type 의 distinguish, validation pipeline.
|
||||
**언제 X**: 매 simple script, runtime-only language (Python, JS).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Cast 의 brand 의 bypass**: 매 type safety 의 break.
|
||||
- **Brand 의 너무 많음**: 매 cognitive overhead.
|
||||
- **Runtime check 없음 의 external input**: 매 brand 만 의 false security.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (ts-brand npm, Effect-TS Brand docs, Zod 4.x).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — ts-brand 의 API, Zod integration, patterns 의 expand |
|
||||
Reference in New Issue
Block a user