patmood / pocketbase-typegen

Typescript generation for pocketbase records
https://www.npmjs.com/package/pocketbase-typegen
512 stars 16 forks source link

JSON datatype breaks expand #96

Closed skowrons closed 8 months ago

skowrons commented 8 months ago

Describe the bug When I have a JSON field in pocketbase it will break typescript when using expansion: Property 'XXX' does not exist on type '{}'.

Steps to reproduce

  1. Create a pocketbase two collections
  2. One collections needs two fields: one json type field and one relation to the other collection
  3. Use the generator: e.x. npx pocketbase-typegen --db ./pb_data/data.db --out packages/core/api/models.ts
  4. Create the expand type:
export type expandedtype = FirstTableResponse<{
  relationField: RelationTableResponse;
}>;
  1. See the error when using the type:
x.expand?.relationField?.xxx

Versions pocketbase-typegen version: 1.2.1 pocketbase version: 0.18.2

skowrons commented 8 months ago

One example from my app of the generated type:

export type ProjectsTasksResponse<Tdescription = unknown, Texpand = unknown> = Required<ProjectsTasksRecord<Tdescription>> & BaseSystemFields<Texpand>
skowrons commented 8 months ago

Sry I have found my error. Just put two types in the generic. 😅

export type expandedtype = FirstTableResponse<{...your json definition...}, {
  relationField: RelationTableResponse;
}>;