Skip to content

Commit

Permalink
Merge pull request #1975 from strapi/dev/autogenerate-updates
Browse files Browse the repository at this point in the history
Update docs for autogenerate settings for JS projects
  • Loading branch information
meganelacheny authored Jan 24, 2024
2 parents 9979c26 + 8789a52 commit 9381ab2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 28 deletions.
32 changes: 6 additions & 26 deletions docusaurus/docs/dev-docs/configurations/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,20 @@ TypeScript-enabled Strapi applications have a specific [project structure](/dev-

## Strapi-specific configuration for TypeScript

:::caution 🚧 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.

To avoid having to [manually generate types](/dev-docs/typescript#generate-typings-for-project-schemas) every time the server restarts, an optional `config/typescript.js|ts` configuration file can be added, which currently accepts only one parameter:
To avoid having to [manually generate types](/dev-docs/typescript#generate-typings-for-project-schemas) 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`:

| Parameter | Description | Type | Default |
| -------------- | -------------------------------------------------------------- | --------- | ------- |
| `autogenerate` | Enable or disable automatic types generation on server restart | `Boolean` | `false` |

**Example:**

<Tabs groupId="js-ts">

<TabItem value="javascript" label="JavaScript">
| `autogenerate` | Enable or disable automatic types generation on server restart | `Boolean` | `true` |

```js title="./config/typescript.js"
module.exports = ({ env }) => ({
autogenerate: true,
});
```

</TabItem>

<TabItem value="typescript" label="TypeScript">

```ts title="./config/typescript.ts"
export default ({ env }) => ({
autogenerate: true,
autogenerate: false,
});
```

</TabItem>

</Tabs>
:::caution 🚧 Experimental.
Turning off types autogeneration for JavaScript projects is considered experimental and might have issues or break some features.
:::
4 changes: 2 additions & 2 deletions docusaurus/docs/dev-docs/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ yarn strapi ts:generate-types --debug #optional flag to display additional loggi
</TabItem>
</Tabs>

:::tip Tip: Automatically generate types
Types can be automatically generated on server restart by adding `autogenerate: true` to [the `config/typescript.js|ts` configuration file](/dev-docs/configurations/typescript#strapi-specific-configuration-for-typescript).
:::tip Tip: Types generation for JavaScript projects
For JavaScript projects, automatic types generation can be turned off (see [`config/typescript.js` documentation](/dev-docs/configurations/typescript#strapi-specific-configuration-for-typescript)).
:::

:::tip Tip: Using types in your front-end application
Expand Down

0 comments on commit 9381ab2

Please sign in to comment.