Skip to content

Commit

Permalink
Use more normal callback definition.
Browse files Browse the repository at this point in the history
  • Loading branch information
wjhsf committed Oct 27, 2023
1 parent 0fec493 commit a7a84f3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
11 changes: 4 additions & 7 deletions lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
/** A callback function that expects an error to be passed. */
export type ErrorCallback = (error: Error, result?: never) => void

/** A callback function that expects a successful result. */
type SuccessCallback<T> = (error: null, result: T) => void

/** A callback function that accepts an error or a result. */
export type Callback<T> = SuccessCallback<T> & ErrorCallback
export interface Callback<T> {
(error: Error, result?: never): void
(error: null, result: T): void
}

/** Safely converts any value to string, using the value's own `toString` when available. */
export const safeToString = (val: unknown) => {
Expand Down
4 changes: 2 additions & 2 deletions lib/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ SOFTWARE.
************************************************************************************ */

import { ErrorCallback, safeToString } from './utils'
import { Callback, safeToString } from './utils'

/* Validation functions copied from check-types package - https://www.npmjs.com/package/check-types */

Expand Down Expand Up @@ -68,7 +68,7 @@ export function isInteger(data: unknown): boolean {
*/
export function validate(
bool: boolean,
cbOrMessage?: ErrorCallback | string,
cbOrMessage?: Callback<never> | string,
message?: string,
): void {
if (bool) return // Validation passes
Expand Down

0 comments on commit a7a84f3

Please sign in to comment.