Declaration Files (.d.ts)
TS · Modules & Declaration Filessyntax
// filename.d.ts
declare function fn(param: Type): ReturnType;
declare const value: Type;example
// global.d.ts
declare function trackEvent(name: string, data?: Record<string, unknown>): void;
declare const APP_VERSION: string;
declare interface ImportMeta {
env: {
VITE_API_URL: string;
VITE_DEBUG: string;
};
}output
// .d.ts files provide type info without runtime codeNote Declaration files describe the shape of existing JavaScript code. They contain only type information — no executable code. TypeScript automatically picks up .d.ts files in your project. Most npm packages include their own or have a @types/package companion.