utils.ts 636 B

12345678910111213141516171819202122
  1. export type FunctionPropertyNames<T> = {
  2. [K in keyof T]: T[K] extends Function ? K : never
  3. }[keyof T]
  4. export type FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>>
  5. export type PickWith<T, KT extends keyof T, V> = {
  6. [P in KT]: T[P] extends V ? V : never
  7. }
  8. export type PickWithOpt<T, KT extends keyof T, V> = {
  9. [P in KT]?: T[P] extends V ? V : never
  10. }
  11. // https://github.com/krzkaczor/ts-essentials Rocks!
  12. export type DeepPartial<T> = {
  13. [P in keyof T]?: T[P] extends Array<infer U>
  14. ? Array<DeepPartial<U>>
  15. : T[P] extends ReadonlyArray<infer U>
  16. ? ReadonlyArray<DeepPartial<U>>
  17. : DeepPartial<T[P]>
  18. };