提交学习笔记专用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
2.2 KiB

  1. type TypeGuard<A, B extends A> = (payload: A) => payload is B;
  2. /**
  3. * A factory function that creates a function to check if the payload is one of the given types.
  4. *
  5. * @example
  6. * import { isOneOf, isNull, isUndefined } from 'is-what'
  7. *
  8. * const isNullOrUndefined = isOneOf(isNull, isUndefined)
  9. *
  10. * isNullOrUndefined(null) // true
  11. * isNullOrUndefined(undefined) // true
  12. * isNullOrUndefined(123) // false
  13. */
  14. export declare function isOneOf<A, B extends A, C extends A>(a: TypeGuard<A, B>, b: TypeGuard<A, C>): TypeGuard<A, B | C>;
  15. /**
  16. * A factory function that creates a function to check if the payload is one of the given types.
  17. *
  18. * @example
  19. * import { isOneOf, isNull, isUndefined } from 'is-what'
  20. *
  21. * const isNullOrUndefined = isOneOf(isNull, isUndefined)
  22. *
  23. * isNullOrUndefined(null) // true
  24. * isNullOrUndefined(undefined) // true
  25. * isNullOrUndefined(123) // false
  26. */
  27. export declare function isOneOf<A, B extends A, C extends A, D extends A>(a: TypeGuard<A, B>, b: TypeGuard<A, C>, c: TypeGuard<A, D>): TypeGuard<A, B | C | D>;
  28. /**
  29. * A factory function that creates a function to check if the payload is one of the given types.
  30. *
  31. * @example
  32. * import { isOneOf, isNull, isUndefined } from 'is-what'
  33. *
  34. * const isNullOrUndefined = isOneOf(isNull, isUndefined)
  35. *
  36. * isNullOrUndefined(null) // true
  37. * isNullOrUndefined(undefined) // true
  38. * isNullOrUndefined(123) // false
  39. */
  40. export declare function isOneOf<A, B extends A, C extends A, D extends A, E extends A>(a: TypeGuard<A, B>, b: TypeGuard<A, C>, c: TypeGuard<A, D>, d: TypeGuard<A, E>): TypeGuard<A, B | C | D | E>;
  41. /**
  42. * A factory function that creates a function to check if the payload is one of the given types.
  43. *
  44. * @example
  45. * import { isOneOf, isNull, isUndefined } from 'is-what'
  46. *
  47. * const isNullOrUndefined = isOneOf(isNull, isUndefined)
  48. *
  49. * isNullOrUndefined(null) // true
  50. * isNullOrUndefined(undefined) // true
  51. * isNullOrUndefined(123) // false
  52. */
  53. export declare function isOneOf<A, B extends A, C extends A, D extends A, E extends A, F extends A>(a: TypeGuard<A, B>, b: TypeGuard<A, C>, c: TypeGuard<A, D>, d: TypeGuard<A, E>, e: TypeGuard<A, F>): TypeGuard<A, B | C | D | E | F>;
  54. export {};