Skip to content

Commit 50b1dd3

Browse files
committed
docs(README): add documentation for improveTypes option
1 parent d8c9780 commit 50b1dd3

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,24 @@ The loader will also automatically convert the value into a slug to be easily us
108108
It's recommended to use e.g. the title of the entry to be easily searchable and readable.
109109
**Do not use e.g. rich text fields as ids.**
110110

111+
### Improved type safety
112+
113+
By default PocketBase reports `number` and `boolean` fields as not required.
114+
This means that the loader will add `undefined` to the type of these fields.
115+
If you want to enforce that these fields are always present, you can set the `improveTypes` option to `true`.
116+
117+
```ts
118+
const blog = defineCollection({
119+
loader: pocketbaseLoader({
120+
...options,
121+
improveTypes: true
122+
})
123+
});
124+
```
125+
126+
This will remove `undefined` from the type of these fields and provide default values with `0` and `false` respectively.
127+
PocketBase will also use these default values when creating new entries in the dashboard.
128+
111129
## Type generation
112130

113131
The loader can automatically generate types for your collection.
@@ -167,6 +185,7 @@ This manual schema will **always override the automatic type generation**.
167185
| `superuserCredentials` | `{ email: string, password: string }` | | The email and password of the superuser of the PocketBase instance. This is used for automatic type generation. |
168186
| `localSchema` | `string` | | The path to a local schema file. This is used for automatic type generation. |
169187
| `jsonSchemas` | `Record<string, z.ZodSchema>` | | A record of Zod schemas to use for type generation of `json` fields. |
188+
| `improveTypes` | `boolean` | | Whether to improve the types of `number` and `boolean` fields, removing `undefined` from them. |
170189

171190
## Special cases
172191

0 commit comments

Comments
 (0)