Skip to main content

TypeScript configuration

Page summary:

TypeScript configuration explains the project’s tsconfig files, output directories, and an optional config/typescript.js file that controls automatic type generation in JavaScript projects. This documentation explains which folders store compiled code and how to toggle this experimental feature.

TypeScript-enabled Strapi projects have a specific project structure and handle TypeScript project configuration through tsconfig.json files.

Strapi also has dedicated TypeScript features that are configured in the config/typescript.js file.

Project structure and TypeScript-specific configuration files​

TypeScript-enabled Strapi applications have a specific project structure with the following dedicated folders and configuration files:

TypeScript-specific directories and filesLocationPurpose
./dist directoryapplication rootAdds the location for compiling the project JavaScript source code.
build directory./distContains the compiled administration panel JavaScript source code. The directory is created on the first yarn build or npm run build command
tsconfig.json fileapplication rootManages TypeScript compilation for the server.
tsconfig.json file./src/admin/Manages TypeScript compilation for the admin panel.

Strapi-specific configuration for TypeScript​

🚧 This feature is considered experimental.

These settings are considered experimental and might have issues or break some features.

Types generated by Strapi are based on the user project structure. Once the type definitions are emitted into their dedicated files, Strapi reads the type definitions to adapt the autocompletion results accordingly.

TypeScript projects (projects with a tsconfig.json file at the root) always generate types each time strapi develop starts or restarts the server. JavaScript projects do the same unless automatic type generation is disabled. strapi start never generates types, and strapi ts:generate-types always does.

To disable automatic type generation for a JavaScript project, add an optional config/typescript.js configuration file, which currently accepts only one parameter:

ParameterDescriptionTypeDefault
autogenerateEnable or disable automatic types generation when running strapi develop (JavaScript projects only)Booleantrue

Example:

./config/typescript.js
module.exports = ({ env }) => ({
autogenerate: false,
});
Was this page helpful?