development.d.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * Wrap a function or class to show a deprecation message when first called.
  3. *
  4. * > 👉 **Important**: only shows a message when the `development` condition is
  5. * > used, does nothing in production.
  6. *
  7. * When the resulting wrapped `fn` is called, emits a warning once to
  8. * `console.error` (`stderr`).
  9. * If a code is given, one warning message will be emitted in total per code.
  10. *
  11. * @template {Function} T
  12. * Function or class kind.
  13. * @param {T} fn
  14. * Function or class.
  15. * @param {string} message
  16. * Message explaining deprecation.
  17. * @param {string | null | undefined} [code]
  18. * Deprecation identifier (optional); deprecation messages will be generated
  19. * only once per code.
  20. * @returns {T}
  21. * Wrapped `fn`.
  22. */
  23. export function deprecate<T extends Function>(
  24. fn: T,
  25. message: string,
  26. code?: string | null | undefined
  27. ): T
  28. /**
  29. * Assert deep strict equivalence.
  30. *
  31. * > 👉 **Important**: only asserts when the `development` condition is used,
  32. * > does nothing in production.
  33. *
  34. * @template {unknown} T
  35. * Expected kind.
  36. * @param {unknown} actual
  37. * Value.
  38. * @param {T} expected
  39. * Baseline.
  40. * @param {Error | string | null | undefined} [message]
  41. * Message for assertion error (default: `'Expected values to be deeply equal'`).
  42. * @returns {asserts actual is T}
  43. * Nothing; throws when `actual` is not deep strict equal to `expected`.
  44. * @throws {AssertionError}
  45. * Throws when `actual` is not deep strict equal to `expected`.
  46. */
  47. export function equal<T extends unknown>(
  48. actual: unknown,
  49. expected: T,
  50. message?: Error | string | null | undefined
  51. ): asserts actual is T
  52. /**
  53. * Assert if `value` is truthy.
  54. *
  55. * > 👉 **Important**: only asserts when the `development` condition is used,
  56. * > does nothing in production.
  57. *
  58. * @param {unknown} value
  59. * Value to assert.
  60. * @param {Error | string | null | undefined} [message]
  61. * Message for assertion error (default: `'Expected value to be truthy'`).
  62. * @returns {asserts value}
  63. * Nothing; throws when `value` is falsey.
  64. * @throws {AssertionError}
  65. * Throws when `value` is falsey.
  66. */
  67. export function ok(
  68. value: unknown,
  69. message?: Error | string | null | undefined
  70. ): asserts value
  71. /**
  72. * Assert that a code path never happens.
  73. *
  74. * > 👉 **Important**: only asserts when the `development` condition is used,
  75. * > does nothing in production.
  76. *
  77. * @param {Error | string | null | undefined} [message]
  78. * Message for assertion error (default: `'Unreachable'`).
  79. * @returns {never}
  80. * Nothing; always throws.
  81. * @throws {AssertionError}
  82. * Throws when `value` is falsey.
  83. */
  84. export function unreachable(message?: Error | string | null | undefined): never