feat: add ability to opt out of type gen declare statement (#3765)
* feat: add ability to opt out of type gen declare statement * chore: docs wording
This commit is contained in:
@@ -18,6 +18,32 @@ 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
|
||||
|
||||
By default, `generate:types` will add a `declare` statement to your types file, which automatically enables type inference within Payload.
|
||||
|
||||
If you are using your `payload-types.ts` file in other repos, though, it might be better to disable this `declare` statement, so that you don't get any TS errors in projects that use your Payload types, but do not have Payload installed.
|
||||
|
||||
```ts
|
||||
// payload.config.ts
|
||||
{
|
||||
// ...
|
||||
typescript: {
|
||||
declare: false, // defaults to true if not set
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
If you do disable the `declare` pattern, you'll need to manually add a `declare` statement to your code in order for Payload types to be recognized. Here's an example showing how to declare your types in your `payload.config.ts` file:
|
||||
|
||||
```ts
|
||||
import { Config } from './payload-types'
|
||||
|
||||
declare module 'payload' {
|
||||
export interface GeneratedTypes extends Config {}
|
||||
}
|
||||
```
|
||||
|
||||
### Custom output file path
|
||||
|
||||
You can specify where you want your types to be generated by adding a property to your Payload config:
|
||||
|
||||
Reference in New Issue
Block a user