maltejur / directus-extension-generate-types

Create types for your directus project in your favourite language.
Other
199 stars 24 forks source link

fix: typescript many relation array #22

Closed stafyniaksacha closed 1 year ago

stafyniaksacha commented 1 year ago

This fix many relations arrays declaration to also take the identifier field

before:

export type TableA = {
  //...
}

export type TableB = {
  table_a: string | TableA[] // string is not an array here
}

after:

export type TableA = {
  //...
}

export type TableB = {
  table_a: (string | TableA)[]
}
maltejur commented 1 year ago

I think you mention the same issue as https://github.com/maltejur/directus-extension-generate-types/issues/21, but the solution seems to be a different one. The type "string" in this case is just generated wrong and I should use the any[] type instead. So with your example it would be:

export type TableB = {
  table_a: any[] | TableA[]
}

See that issue for more information on this. I will just push the correct fix soon and thus close you pr, but still thanks a lot for noticing and creating this pr.