Skip to main content

TypeScript configuration

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|ts 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

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.

To avoid having to manually generate types every time the server restarts, TypeScript-based projects autogenerate the types for you. However, generating types is not a requirement for JavaScript-based projects, so if you want you can turn types autogeneration off by creating an optional config/typescript.js|ts configuration file and setting the autogenerate parameter to false:

ParameterDescriptionTypeDefault
autogenerateEnable or disable automatic types generation on server restartBooleantrue
./config/typescript.js
module.exports = ({ env }) => ({
autogenerate: false,
});
🚧 Experimental.

Turning off types autogeneration for JavaScript projects is considered experimental and might have issues or break some features.