diff --git a/docs/developer-docs/latest/development/typescript.md b/docs/developer-docs/latest/development/typescript.md index 1896941f28..a157dff245 100644 --- a/docs/developer-docs/latest/development/typescript.md +++ b/docs/developer-docs/latest/development/typescript.md @@ -42,6 +42,31 @@ yarn develop +## Use TypeScript typings + +Strapi provides typings on the `Strapi` class to improve the TypeScript developing experience. These typings come with an autocomplete feature that automatically offers suggestions while developing. + +To experience TypeScript-based autocomplete while developing Strapi applications, you could try the following: + +1. From your code editor, open the `./src/index.ts` file. +2. In the `register` method, declare the `strapi` argument as of type `Strapi`: + + ```js + // path: ./src/index.ts + + import '@strapi/strapi'; + + export default { + register( {strapi }: { strapi: Strapi }) { + // ... + }, + }; + ``` + +2. Within the body of the `register` method, start typing `strapi.` and use keyboard arrows to browse the available properties. +3. Choose `runLifecyclesfunction` from the list. +4. When the `strapi.runLifecyclesFunctions` method is added, a list of available lifecycle types (i.e. `register`, `bootstrap` and `destroy`) are returned by the code editor. Use keyboard arrows to choose one of them and the code will autocomplete. + ## Develop a plugin using TypeScript New plugins can be generated following the [plugins development documentation](/developer-docs/latest/development/plugins-development.md). There are 2 important distinctions for TypeScript applications: