[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: P-REINFORCE-AI-DU-STATES
|
||||
id: [[P-Reinforce]]-AI-DU-[[State]]S
|
||||
category: "10_Wiki/💡 Topics/AI"
|
||||
confidence_score: 0.99
|
||||
tags: [TypeScript, StateManagement, Patterns, Architecture]
|
||||
tags: [TypeScript, State[[Management]], Patterns, [[Architecture]]]
|
||||
last_reinforced: 2026-04-20
|
||||
---
|
||||
|
||||
@@ -15,7 +15,7 @@ last_reinforced: 2026-04-20
|
||||
- **The Anti-pattern**:
|
||||
- `interface State { isLoading: boolean; error?: string; data?: Data; }`
|
||||
- 이 설계는 `isLoading: true`이면서 동시에 `error`가 존재하는 모순된 상태를 허용한다.
|
||||
- **The Discriminated Union Solution**:
|
||||
- **The Discriminated Union [[Solution]]**:
|
||||
- `type State = { type: 'loading' } | { type: 'error'; message: string } | { type: 'success'; data: Data };`
|
||||
- `type` 속성을 통해 현재 어떤 상태인지 명확히 구별하며, 각 상태에 꼭 필요한 데이터만 가질 수 있게 강제한다.
|
||||
- **Benefit**: 컴포넌트나 로직에서 조건문 분기가 매우 명확해지며, 런타임 에러 발생 가능성이 획기적으로 줄어든다.
|
||||
|
||||
Reference in New Issue
Block a user