typeutils.ts 483 B

1234567891011121314151617181920
  1. export type FieldEquals<T, K extends keyof T, Vals extends T[K][]> = {
  2. // eslint-disable-next-line
  3. [_x in K]: Vals[number]
  4. }
  5. export const objectFieldIncludes = <
  6. T,
  7. K extends keyof T,
  8. V extends readonly T[K][]
  9. >(
  10. obj: T,
  11. field: K,
  12. values: V
  13. // eslint-disable-next-line
  14. ): obj is T & { [_x in K]: V[number] } => values.includes(obj[field])
  15. export const valueIncludes = <T, V extends readonly T[]>(
  16. obj: T,
  17. values: V
  18. ): obj is V[number] => values.includes(obj)