Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript doesn't suggests the props using Pick or Omit #874

Closed
yanmifeakeju opened this issue May 16, 2024 · 1 comment
Closed

Typescript doesn't suggests the props using Pick or Omit #874

yanmifeakeju opened this issue May 16, 2024 · 1 comment

Comments

@yanmifeakeju
Copy link

I've noticed that when using TypeScript in our project, the IDE doesn't suggest props when utilizing the Pick or Omit methods. I have a feeling that this functionality used to be available before.

Any insights on why this feature is no longer working or if I may be mistaken about its previous availability

@sinclairzx81
Copy link
Owner

sinclairzx81 commented May 24, 2024

@yanmifeakeju Hi, sorry for the delay in reply.

TypeBox previously inferred Pick/Omit and Index property keys, however it was removed on 0.32.x as the inference required to obtain the keys was proving very expensive (as TB needed to either Static or derive keys during composition (which was a problem for very deeply nested / computed types)), also the exact property key values resulted in a few issues when using Pick/Omit/Index in generic functions (where keys are passed as generic arguments)

As of 0.32.0, TypeBox allows passing any keys, however you should check the return value of Omit/Pick and Index to ensure the operation produced the expected type.

import { Type } from '@sinclair/typebox'

const T = Type.Object({
  x: Type.Number(),
  y: Type.Number()
})

// As of 0.32.x...

const A = Type.Pick(T, ['z'])  // TObject<{}>

const B = Type.Omit(T, ['z'])  // TObject<{ a: TNumber, b: TNumber }>

const C = Type.Index(T, ['z']) // TNever

Hope this provides some insight into the change. Will close off this issue for now, but if you have any additional questions on the above, feel free to ping on this thread.

All the best
S

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants