TypeScript Declaration Files

Wildcard ambient module declaration

A pattern ambient module supplies a shared static contract for matching import names. It may accept an import even when the asset is absent, so it neither verifies asset existence nor installs a loader. Match the declaration to the actual bundler output. This example only checks types. Baseline: TypeScript 5.8.3. File labels are explanatory; create the files separately.

Formal Syntax & Structure

typescript syntaxtypescript
declare module "*.extension" { /* exports */ }

Working Example

Example Snippettypescript
// File: tsconfig.json (omit this label){  "compilerOptions": {    "target": "ES2022",    "module": "CommonJS",    "strict": true,    "types": [],    "noEmit": true,    "skipLibCheck": false,    "lib": [      "ES5"    ]  },  "files": [    "main.ts"  ]}
// File: assets.d.ts (omit this label)declare module "*.css" {  const classes: Readonly<Record<string, string>>;  export default classes;}
// File: main.ts (omit this label)/// <reference path="./assets.d.ts" />import classes from "./theme.css";const checked: string = classes.button;
// Run: tsc -p . --pretty false// Expected: no diagnostics.
TypeScript Reference