Importing ./logo.svg only works because a bundler (or a loader) turns it into JavaScript: a URL string, a CSS Modules class map, a component. tsc can't see that, so on 6.0.3 and 7.0.2 a value import of an unknown file is TS2307. Since TS 6.0 noUncheckedSideEffectImports is on by default, so even import "./global.css" fails, with TS2882.
Two ways to describe what the bundler produces:
- Pattern ambient modules (one
*wildcard). In a.d.tsthat the project includes (a script file, not a module), writedeclare module "*.svg" { const url: string; export default url; }. Any specifier matching the pattern gets that shape.declare module "*.css" {}is enough for side-effect imports. Framework starters often ship these (the TypeScript docs mention Vite'svite-env.d.ts). - Per-file declarations (TS 5.0+). For
./button.module.css,tsclooks forbutton.module.d.css.ts, the pattern{basename}.d.{extension}.ts. It can list the real class names, so typos fail. Using it needsallowArbitraryExtensions; without it 6.0.3 and 7.0.2 report TS6263. CSS Modules tooling can generate these files.
The trade-off: a wildcard is one line and covers everything, but its types are generic ({ readonly [className: string]: string } accepts any class name). Per-file declarations are exact but must be generated and kept in sync.
Both are claims, not checks. The declaration says what the bundler will return; if your bundler is configured differently (an SVG as a React component, say), the types lie. Match the declaration to the loader's real output.