Advertisement
Guest User

Untitled

a guest
May 24th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. /**
  2. * Omit specific properties from an interface. Use `"field1" | "field2"` to
  3. * exclude multiple. This is useful if you are adding a layer over a general
  4. * component and want to exclude specific props from being passed into the
  5. * layer.
  6. *
  7. * Usage:
  8. *
  9. * ```ts
  10. * interface SomeProps {
  11. * field1: string;
  12. * field2: string;
  13. * field3: string;
  14. * }
  15. *
  16. * export interface OmittedProps extends Omit<SomeProps, 'field2' | 'field3'> {
  17. * // Some other props if you wish or just leave empty
  18. * }
  19. *
  20. * export const fewer: FC<OmittedProps> = ({ field1 }) => {
  21. * // Function contents
  22. * }
  23. * ```
  24. */
  25. export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
  26.  
  27. /**
  28. * Include specific properties from an interface. Use `"field1" | "field2"` to
  29. * include ultiple. This is useful if you are adding a layer over a general
  30. * component and want to include only specific props to pass into the layer.
  31. *
  32. * Usage:
  33. *
  34. * ```ts
  35. * interface SomeProps {
  36. * field1: string;
  37. * field2: string;
  38. * field3: string;
  39. * }
  40. *
  41. * export interface IncludedProps extends Include<SomeProps, 'field2' | 'field3'> {
  42. * // Some other props if you wish or just leave empty
  43. * }
  44. *
  45. * export const fewer: FC<IncludedProps> = ({ field2, field3 }) => {
  46. * // Function contents
  47. * }
  48. * ```
  49. */
  50. export type Include<T, K extends keyof T> = Pick<T, Extract<keyof T, K>>;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement