tsc step, a ts-loader, or an extra bundler rule.
Builds do not need the typescript package at all. SWC compiles your sources and strips the types. The package matters only for editor tooling and a tsc --noEmit typecheck. For that reason a missing typescript package never fails a build, unlike missing framework integration packages.
When TypeScript is a good fit
- You want safer refactors and clearer contracts across extension contexts.
- You share logic between background scripts, content scripts, and UI surfaces.
- You need predictable API usage when working with AI-generated code.
Template examples
new-typescript

content-typescript

Generated ambient types
For TypeScript projects, Extension.js generates anextension-env.d.ts file at your project root with ambient declarations (browser/runtime globals, EXTENSION_PUBLIC_* env, and bundler types). Both dev and build regenerate it, so editor types and a CI tsc --noEmit stay in sync. Commit it (or git-ignore it). Either works; itβs recreated on the next run.
Usage with an existing extension
Add TypeScript to an existing extension with the steps below.Installation
- Install TypeScript as a development dependency:
- Initialize the TypeScript configuration file
tsconfig.json:
Configuration
TypeScript detection and requirements
Extension.js looks fortsconfig.json next to your package.json.
.tssource files with notsconfig.jsonis a hard error. Create the file next topackage.jsonto fix it.- A project that declares the
typescriptdependency but has notsconfig.jsonand no.tssources yet gets a baseline one written for it.
moduleResolutionisbundler, which models the Rspack + SWC pipeline. The removednode(node10) mode failstsc --noEmiton TypeScript 7.jsxisreact-jsxonly when Extension.js detects a JSX framework in the project. Without one, it stayspreserve.
Automatic types
Extension.js generatesextension-env.d.ts in your project root during development. This file includes type declarations for Extension.js APIs and browser polyfill types.
Transpilation vs type-checking
The default bundler pipeline compiles TypeScript but does not run fulltsc type-checking as part of bundling.
Recommended scripts:
Next steps
- Learn how Extension.js handles ECMAScript modules.
- Explore styling options like Sass modules.
- Read about JavaScript and TypeScript files in browser extensions.
- Compare TypeScript support across each browser extension framework.

