docs: new and improve lexical docs, hoist up all headings (#6639)

This commit is contained in:
Alessio Gravili
2024-06-05 17:08:15 -04:00
committed by GitHub
parent aee3ee21d1
commit 19f8cbcf76
84 changed files with 1215 additions and 1122 deletions

View File

@@ -8,7 +8,7 @@ keywords: headless cms, typescript, documentation, Content Management System, cm
While building your own custom functionality into Payload, like plugins, hooks, access control functions, custom views, GraphQL queries / mutations, or anything else, you may benefit from generating your own TypeScript types dynamically from your Payload config itself.
### Types generation script
## Types generation script
Run the following command in a Payload project to generate types based on your Payload config:
@@ -18,7 +18,7 @@ payload generate:types
You can run this command whenever you need to regenerate your types, and then you can use these types in your Payload code directly.
### Disable declare statement
## Disable declare statement
By default, `generate:types` will add a `declare` statement to your types file, which automatically enables type inference within Payload.
@@ -44,7 +44,7 @@ declare module 'payload' {
}
```
### Custom output file path
## Custom output file path
You can specify where you want your types to be generated by adding a property to your Payload config:
@@ -61,7 +61,7 @@ You can specify where you want your types to be generated by adding a property t
The above example places your types next to your Payload config itself as the file `generated-types.ts`.
### Example Usage
## Example Usage
For example, let's look at the following simple Payload config:
@@ -123,7 +123,7 @@ export interface Post {
}
```
### Custom Field Interfaces
## Custom Field Interfaces
For `array`, `block`, `group` and named `tab` fields, you can generate top level reusable interfaces. The following group field config:
@@ -170,11 +170,11 @@ export interface Collection1 {
appending the field type to the end, i.e. `MetaGroup` or similar.
</Banner>
### Using your types
## Using your types
Now that your types have been generated, payloads local API will now be typed. It is common for users to want to use this in their frontend code, we recommend generating them with payload and then copying the file over to your frontend codebase. This is the simplest way to get your types into your frontend codebase.
#### Adding an NPM script
### Adding an NPM script
<Banner type="warning">
<strong>Important</strong>