Browsers and bundlers can import files that are not JavaScript: CSS module scripts, JSON, SVG and more. TypeScript cannot read those files, but it can read a declaration file that describes one. For ./theme.css, that file is named theme.d.css.ts, and allowArbitraryExtensions is the option that lets TypeScript use it.
Without the option, TypeScript finds the declaration file and still refuses the import, with TS6263. The option arrived with TypeScript 5.0.
At a glance
| Write | "allowArbitraryExtensions": true when you import CSS, SVG or other non-JavaScript files and write a declaration file for each |
|---|---|
| On the command line | --allowArbitraryExtensions |
| Type | boolean |
| Default in TypeScript 5.9 | false |
| TypeScript's description | Enable importing files with any extension, provided a declaration file is present. |
The description is quoted from TypeScript's own option list (Apache-2.0); see the notices.
Examples
import sheet from "./theme.css" with { type: "css" };error TS6263: Module './theme.css' was resolved to '/project/theme.d.css.ts', but '--allowArbitraryExtensions' is not set.
document.adoptedStyleSheets = [sheet];jsconfig.json for this example
{
"compilerOptions": {
"checkJs": true,
"noEmit": true,
"strict": true,
"target": "es2022",
"module": "nodenext",
"types": [],
"lib": [
"es2022",
"dom"
]
},
"include": [
"*.js"
]
} import sheet from "./theme.css" with { type: "css" };
document.adoptedStyleSheets = [sheet];jsconfig.json for this example
{
"compilerOptions": {
"checkJs": true,
"noEmit": true,
"strict": true,
"target": "es2022",
"module": "nodenext",
"types": [],
"lib": [
"es2022",
"dom"
],
"allowArbitraryExtensions": true
},
"include": [
"*.js"
]
} Naming the declaration file
Put .d before the file's own extension and .ts after it: theme.css → theme.d.css.ts, logo.svg → logo.d.svg.ts. The file describes what the import gives you; for a CSS module script that is one CSSStyleSheet as the default export.
CSS module scripts in the browser
The examples use a CSS module script, a web platform feature: import sheet from "./theme.css" with { type: "css" } gives you a CSSStyleSheet to adopt into the document or a shadow root. Browser support is still uneven, so check MDN before relying on it without a bundler.
One declaration for every file of a kind
The other way to type such imports needs no option: a .d.ts file with declare module "*.css" { … } covers every CSS import at once. Use it when all imports of a kind look the same; use per-file declarations with allowArbitraryExtensions when each file exports something different (CSS modules with class names, for example).
Gotchas
- An import that binds nothing, such as
import "./theme.css", is not checked at all unlessnoUncheckedSideEffectImportsis on. - Declaration files you write are skipped by
skipLibCheck, thejsconfig.jsondefault, so a mistake intheme.d.css.tsgoes unreported.
Sources
- TSConfig Reference: allowArbitraryExtensions · TypeScript
- TypeScript 5.0 release notes · TypeScript handbook
- import attributes (with) · MDN
Last reviewed 20 October 2026.