linefusion / indirectus

20 stars 6 forks source link

Bug: types safety does not work when using instance.createUser() #9

Closed N0SAFE closed 3 weeks ago

N0SAFE commented 2 months ago

Description of the bug

when using the instance created by createTypesClient the function createUser does not have the same type safety as if i do DirectusSDKcreateUser()

type collections = { directus_users: { namteste: Types.Optional }[] }

const directus = createTypedClient('http://localhost:8055')

directus.createUser({ test: 'test', <- error: Object literal may only specify known properties, and 'test' does not exist in type X })

directus.request( DirectusSDK.createUser({ test: 'test', <- no error }) )

Steps To Reproduce

  1. create a new field inside the collection user like test: string
  2. generate the client.ts
  3. use the createTypedClient to generate a new instanceOfDirectus with the custom function
  4. use the function instance.createUser and see that the property test is not infered as a property required in createUser
  5. however: when using the request cunction i have the infered type (directus.request(DirectusDSK.createUser({test: 'test'}))<- no error)

Additional Information

No response

WoLfulus commented 3 weeks ago

Fixed in the next release

image

WoLfulus commented 3 weeks ago

Side note: there's still some cases where the schema type injection will fail, and to automate that part I'll have to add a good chunk of code to the generation engine, which I can't do right now. I'll keep this in mind whenever I have more time to deal with this, for now cases where it fails (like .aggregate), just use .request(aggregate()) instead.

And to be honest, even the SDK itself doesn't handle those types properly, like Partial for creation doesn't make sense at all (required fields are a type mismatch in this case). Would love to support something like Create instead and replace the whole thing instead of proxying types from the SDK.