You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+19
Original file line number
Diff line number
Diff line change
@@ -108,6 +108,24 @@ The loader will also automatically convert the value into a slug to be easily us
108
108
It's recommended to use e.g. the title of the entry to be easily searchable and readable.
109
109
**Do not use e.g. rich text fields as ids.**
110
110
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
+
111
129
## Type generation
112
130
113
131
The loader can automatically generate types for your collection.
@@ -167,6 +185,7 @@ This manual schema will **always override the automatic type generation**.
167
185
|`superuserCredentials`|`{ email: string, password: string }`|| The email and password of the superuser of the PocketBase instance. This is used for automatic type generation. |
168
186
|`localSchema`|`string`|| The path to a local schema file. This is used for automatic type generation. |
169
187
|`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. |
0 commit comments