Files
2nd/10_Wiki/Topics/Architecture/Excess_Property_Checking.md
T
koriweb d8a80f6272 chore(wiki): dangling 링크 canonical 정규화 (768파일/1200건)
이름만 다른(표기 변형) [[위키링크]]를 대상 문서의 canonical 제목으로 치환해
끊겼던 1,200개 링크를 연결. 제목/파일명 정규화 일치만 적용하고 별칭 매칭은
과병합 위험으로 제외(애매성 가드). 원본은 _link_reconcile_backup/ 에 백업.
도구: Datacollect/scripts/link_reconcile_apply.mjs

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-08 12:24:15 +09:00

5.3 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-excess-property-checking Excess Property Checking 10_Wiki/Topics verified self
TypeScript Excess Property
Strict Object Literal
none A 0.9 applied
typescript
type-system
structural-typing
2026-05-10 pending
language framework
typescript none

Excess Property Checking

매 한 줄

"매 fresh object literal 의 only 의 strict property check". TypeScript 매 structural typing 매 normally 의 extra properties 의 allow, 매 but 의 fresh object literal 의 directly 의 typed slot 의 assign 시 매 extra properties 의 error 의 raise. Typo 방지 + intent clarity 의 design choice.

매 핵심

매 Why exists

  • 매 structural typing 매 {a:1, b:2}{a:number} 의 assignable.
  • 매 그러나 매 literal 매 typo 의 high risk — { colour: 'red' }{ color?: string } 매 silent ignore.
  • 매 TS 매 fresh literal 의 special-case — 매 Object literal may only specify known properties 의 error.

매 Fresh-ness 매 lost

  • 매 variable 의 assign 시 매 widened — const x = { extra: 1 }; fn(x) 매 ok.
  • 매 spread 매 fresh-ness 의 keep (TS 4.0+).
  • 매 type assertion as T 매 bypass.
  • 매 index signature [k: string]: ... 매 disable.

매 응용

  1. React props typo detection.
  2. Config object validation.
  3. API request body shape enforcement.
  4. Discriminated union narrowing aid.

💻 패턴

Basic excess error

interface Point { x: number; y: number }
const p: Point = { x: 1, y: 2, z: 3 };
//                              ^^^^ Object literal may only specify known properties

Bypass via intermediate variable

const tmp = { x: 1, y: 2, z: 3 };
const p: Point = tmp; // OK — fresh-ness lost
// Use this only when extra properties are intentional

Index signature 의 opt-out

interface Config {
  name: string;
  [key: string]: unknown; // 매 extra props 의 allow
}
const c: Config = { name: 'x', debug: true, port: 3000 }; // OK

React props 의 typo guard

type ButtonProps = { label: string; onClick: () => void };
function Button(props: ButtonProps) { /* ... */ }

<Button label="Save" onCick={save} />
//                   ^^^^^ Property 'onCick' does not exist
// Excess property check catches typo at JSX call site

Discriminated union with strict checks

type Shape =
  | { kind: 'circle'; radius: number }
  | { kind: 'square'; side: number };

const s: Shape = { kind: 'circle', radius: 5, side: 3 };
//                                              ^^^^ excess
// 매 kind 의 narrow 의 'circle', 매 side 의 not allowed

Spread 의 preserve fresh-ness (TS 4.0+)

type T = { a: number };
const base = { a: 1 };
const x: T = { ...base, b: 2 }; // 매 error — b 의 excess

Optional excess via Exact type emulation

type Exact<T, U extends T> = T & {
  [K in Exclude<keyof U, keyof T>]: never;
};

function strict<T>() {
  return <U extends T>(x: Exact<T, U>): T => x as T;
}

const point = strict<Point>()({ x: 1, y: 2, z: 3 });
//                                             ^^^^ Type 'number' is not assignable to 'never'
// 매 variable assign path 의 also 의 strict

Util: 매 satisfies operator (TS 4.9+)

const config = {
  endpoint: 'https://api.example.com',
  timeout: 5000,
  retries: 3,
} satisfies { endpoint: string; timeout: number };
//             ^^^^ 매 retries 의 excess error

매 결정 기준

상황 Approach
Config / DTO literal 매 default check 의 leverage
Plugin system 의 unknown extras 매 index signature 의 add
Test fixture 의 extra debug fields 매 intermediate var 또는 as
매 strict 의 want 의 variable path Exact helper 또는 satisfies
Library author 의 strict API satisfies 또는 nominal brand

기본값: 매 default behavior 의 leverage — 매 typo 매 catch. 매 escape 매 minimize, 매 satisfies 의 prefer.

🔗 Graph

🤖 LLM 활용

언제: 매 typo-prone literal — config, props, API body. Schema-bound inputs. 언제 X: 매 plugin / metadata 의 extra props 매 intentional — 매 index signature 의 add.

안티패턴

  • as T 의 bypass habit: 매 error 의 mask, 매 typo 의 ship — 매 fix 의 root cause.
  • Index signature 의 over-permissive: 매 모든 class 매 [k: string]: any 의 add — 매 type safety 의 destroy.
  • Intermediate var 의 escape: 매 const x = {...}; fn(x) 매 intent 의 obscure — 매 명시적 cast 의 prefer.
  • satisfies 의 ignore: 매 TS 4.9+ 매 widening 없는 strict literal 의 best tool — 매 underused.

🧪 검증 / 중복

  • Verified (TS handbook "Object Types"; TS 4.9 release notes).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — excess property check + satisfies/Exact patterns