d5243200f663e56f7be9c82c3776b66a4768dd79bd95614a3cb63521233a6fa0dd297ef3d9d01d91feec4a0def4b6d2d3937657c44953492d5efe68ec7c982 933 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import {ConditionalKeys} from './conditional-keys';
  2. /**
  3. Pick keys from the shape that matches the given `Condition`.
  4. This is useful when you want to create a new type from a specific subset of an existing type. For example, you might want to pick all the primitive properties from a class and form a new automatically derived type.
  5. @example
  6. ```
  7. import {Primitive, ConditionalPick} from 'type-fest';
  8. class Awesome {
  9. name: string;
  10. successes: number;
  11. failures: bigint;
  12. run() {}
  13. }
  14. type PickPrimitivesFromAwesome = ConditionalPick<Awesome, Primitive>;
  15. //=> {name: string; successes: number; failures: bigint}
  16. ```
  17. @example
  18. ```
  19. import {ConditionalPick} from 'type-fest';
  20. interface Example {
  21. a: string;
  22. b: string | number;
  23. c: () => void;
  24. d: {};
  25. }
  26. type StringKeysOnly = ConditionalPick<Example, string>;
  27. //=> {a: string}
  28. ```
  29. */
  30. export type ConditionalPick<Base, Condition> = Pick<
  31. Base,
  32. ConditionalKeys<Base, Condition>
  33. >;