Docusaurus is written in TypeScript and ships first-class TypeScript support. You can type your configuration file, write TypeScript theme components, and runDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/facebook/docusaurus/llms.txt
Use this file to discover all available pages before exploring further.
tsc as part of your CI pipeline. The minimum required TypeScript version is 5.1.
Starting a TypeScript project
If you are creating a new site, pass the--typescript flag to create-docusaurus to scaffold a fully typed project from the start:
Setting up TypeScript in an existing project
Install the required packages
Add the TypeScript compiler and the Docusaurus type packages as dev dependencies:
- npm
- yarn
Typing docusaurus.config.ts
You can renamedocusaurus.config.js to docusaurus.config.ts and use the Config type from @docusaurus/types to get full editor autocomplete and compile-time validation:
docusaurus.config.ts
satisfies operator (TypeScript 4.9+) lets you keep type checking while still inferring the precise type of each field. Import Preset.Options and Preset.ThemeConfig from @docusaurus/preset-classic for the preset-specific types.
JSDoc annotations for .js files
If you prefer to keep a.js config file, you can still get type checking with JSDoc annotations and a // @ts-check comment:
docusaurus.config.js
Running a type check
Add atypecheck script to your package.json:
package.json
yarn workspace website typecheck as part of its own CI checks.
tsc with the @docusaurus/tsconfig base does not emit output files — it only type-checks. Your site is still built by the Docusaurus bundler (webpack or Rspack), not by tsc.Ambient types for optional plugins
Some plugins and themes ship ambient.d.ts files that TypeScript does not load automatically. For example, importing from @theme/Playground (provided by @docusaurus/theme-live-codeblock) produces TS2307: Cannot find module '@theme/Playground' until you opt in to that plugin’s types.
The recommended approach is a triple-slash reference in a project-level .d.ts file:
src/types.d.ts
types compiler option in tsconfig.json:
tsconfig.json
Typing swizzled components
When you swizzle a component, you can request TypeScript source by adding the--typescript flag:
src/theme/Footer/index.tsx (and styles.module.css where applicable) instead of a .js file.
All official Docusaurus themes support TypeScript theme components, including:
@docusaurus/theme-classic@docusaurus/theme-live-codeblock@docusaurus/theme-search-algolia
src/theme/Footer/index.tsx
WrapperProps<typeof FooterType> derives the correct prop types from the original component’s type definition, so your wrapper stays in sync automatically when the upstream props change.
If you are authoring a Docusaurus theme package and want to add TypeScript support for swizzlable components, implement the
getTypeScriptThemePath lifecycle API. See the Lifecycle APIs documentation for details.