"매 type-only declarations — 매 describe shapes that exist elsewhere". 매 TypeScript (Anders Hejlsberg, 2012) 매 since v0.8 매 .d.ts files. 매 DefinitelyTyped (2014) → @types/* npm scope (2016) → TS 4.x package "exports" + types (2021) → TS 5.7 (2026 stable) 매 --isolatedDeclarations 매 fast .d.ts emit.
매 핵심
매 ambient 의 의미
Ambient: 매 declaration only, 매 no implementation. 매 emit 매 not 매 produce JS.
.d.ts files: 매 declarations only. 매 imports 매 type-erased.
declare keyword: 매 inside .ts files 매 declare 매 ambient binding.
매 use cases
Type 3rd-party JS library (no built-in types).
Type global runtime (browser, Node, custom).
Augment existing module/global.
Distribute types separate from JS (npm "types" field).
Emit minimal API surface from TS source.
매 응용
@types/ packages* — DefinitelyTyped community types.
Global augmentation — extend Window, process.env.
Module augmentation — add methods to existing module's interface.
// types/globals.d.ts
declareglobal{var__APP_VERSION__: string;interfaceWindow{analytics?:{track(event: string,props?: object):void};}namespaceNodeJS{interfaceProcessEnv{DATABASE_URL: string;REDIS_URL: string;}}}export{};// 매 file 의 module 의 만듦 — augmentation 매 valid
Module augmentation (extend existing)
// add-toJSON.d.ts
import"express";declaremodule"express"{interfaceRequest{user?:{id: string;role:"admin"|"user"};requestId: string;}}// Now in any file: req.user is typed
언제: 매 untyped JS interop, 매 global runtime typing, 매 library distribution, 매 framework extension points.
언제 X: 매 internal TS code (use regular interface/type), 매 enforcement need (declarations 매 erased — runtime check 매 separate).
❌ 안티패턴
any everywhere in .d.ts: 매 type loss 의 propagation. 매 unknown + narrow.
Augmenting without export {}: 매 file 매 script 의 treated, 매 augmentation silently fails.
Triple-slash in modern code: 매 prefer tsconfig "types" array.
Global pollution: 매 every helper 매 global 의 declare → namespace clashes.