Files
2nd/10_Wiki/Topic_Programming/Frontend/Declaration-Files.md
T
Antigravity Agent 9148c358d0 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 폴더 제거.
2026-07-05 00:33:48 +09:00

5.6 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-declaration-files Declaration Files 10_Wiki/Topics verified self
TypeScript .d.ts
Type Definitions
DefinitelyTyped
none A 0.9 applied
typescript
types
declaration
dts
2026-05-10 pending
language framework
TypeScript TypeScript 5.x

Declaration Files

매 한 줄

"매 .d.ts = type-only public surface — runtime code 의 X.". 매 TypeScript의 매 declaration 파일이 매 JS library의 매 type contract 의 제공 — @types/node, @types/react 등 매 DefinitelyTyped 가 매 ecosystem 의 backbone. 매 modern (2024-2026) 워크플로우는 tsc --declaration 자동 생성 + tsup / rollup-plugin-dts 의 bundling.

매 핵심

매 file types

  • lib.d.ts — TS standard library (DOM, ES2024).
  • package.d.ts — package 자체 type.
  • globals.d.ts — ambient declaration (window 확장).
  • module.d.tsdeclare module 'foo' shape.

매 publishing

  • package.json "types" (or "typings") field → main d.ts entry.
  • "exports" map (Node 16+) — multiple entry points + types.
  • Dual ESM/CJS = 매 두 d.ts 필요 — "types" per condition.

매 응용

  1. JS library 의 type 추가 — @types/foo.
  2. Module augmentation — declare module 'react' { ... }.
  3. CSS modules / image import — *.module.css declaration.
  4. Env variable typing — import.meta.env.

💻 패턴

1. Basic .d.ts

// lib.d.ts
export interface User { id: string; name: string }
export declare function getUser(id: string): Promise<User>;
export declare const VERSION: string;

2. Module declaration (ambient)

// types/legacy-lib.d.ts
declare module 'legacy-lib' {
  export function init(opts: { key: string }): void;
  const version: string;
  export default version;
}

3. Module augmentation

// types/react-augment.d.ts
import 'react';
declare module 'react' {
  interface CSSProperties {
    '--brand-hue'?: string;
  }
}

4. Global augmentation

// types/globals.d.ts
declare global {
  interface Window {
    analytics?: { track(event: string, props?: Record<string, unknown>): void };
  }
}
export {}; // make this a module

5. Asset module declarations

// types/assets.d.ts
declare module '*.module.css' {
  const classes: Record<string, string>;
  export default classes;
}
declare module '*.svg' {
  const url: string;
  export default url;
}
declare module '*.svg?react' {
  import { FC, SVGProps } from 'react';
  const Component: FC<SVGProps<SVGSVGElement>>;
  export default Component;
}

6. Vite env types

// src/vite-env.d.ts
/// <reference types="vite/client" />
interface ImportMetaEnv {
  readonly VITE_API_URL: string;
  readonly VITE_SENTRY_DSN: string;
}
interface ImportMeta { readonly env: ImportMetaEnv }

7. package.json exports + types (dual ESM/CJS)

{
  "name": "@acme/lib",
  "type": "module",
  "main": "./dist/index.cjs",
  "module": "./dist/index.js",
  "types": "./dist/index.d.ts",
  "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "import": "./dist/index.js",
      "require": "./dist/index.cjs"
    },
    "./feature": {
      "types": "./dist/feature.d.ts",
      "import": "./dist/feature.js"
    }
  }
}

8. tsconfig for d.ts emit

{
  "compilerOptions": {
    "declaration": true,
    "declarationMap": true,
    "emitDeclarationOnly": false,
    "outDir": "dist",
    "rootDir": "src",
    "moduleResolution": "bundler"
  }
}

9. tsup d.ts bundle

// tsup.config.ts
import { defineConfig } from 'tsup';
export default defineConfig({
  entry: ['src/index.ts'],
  format: ['esm', 'cjs'],
  dts: true,           // bundle d.ts
  sourcemap: true,
  clean: true,
});

10. Conditional type for string literal API

// route.d.ts — type-safe routing
type Route =
  | { name: 'home'; params?: undefined }
  | { name: 'user'; params: { id: string } };

declare function navigate<R extends Route>(...args: R['params'] extends undefined ? [name: R['name']] : [name: R['name'], params: R['params']]): void;

매 결정 기준

상황 Approach
매 JS library 의 type @types/foo (DefinitelyTyped).
매 own library tsc --declaration or tsup dts: true.
매 monorepo internal composite: true + project references.
매 CSS / asset import *.module.css ambient declaration.
Plugin-based extension Module augmentation.

기본값: tsup dts: true + exports map + declarationMap.

🔗 Graph

🤖 LLM 활용

언제: 매 d.ts scaffolding, ambient module declaration, exports map. 언제 X: 매 complex generic inference debug — 매 TS playground 사용.

안티패턴

  • No export {} in global aug: 매 file 이 script 로 처리됨 → 매 declare global 무효.
  • any everywhere: 매 d.ts 의 가치 의 negate.
  • types 미게시: 매 user 의 @types/foo 의 별도 작성 필요.
  • Conditional exports types last: 매 "types" 가 매 conditions 의 first 위치 — 매 spec.

🧪 검증 / 중복

  • Verified (typescriptlang.org/docs/handbook/declaration-files, TS 5.x release notes).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — d.ts authoring + exports map 2026