Skip to content

Commit

Permalink
feat: replace null with undefined (#41)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Return `undefined` instead of `null` for default value to allow reassignment when destructuring
  • Loading branch information
sujyotraut authored Apr 12, 2024
1 parent 6776217 commit 9c71c95
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export type NoTryResult<T, E = Error> = [E | null, T | null];
export type NoTryResult<T, E = Error> = [E | undefined, T | undefined];

function noop(): void {
return null;
return undefined;
}

export function noTry<T, E = Error>(fn: () => T, handleErr: (error: E) => void = noop): NoTryResult<T, E> {
const result: NoTryResult<T, E> = [null, null];
const result: NoTryResult<T, E> = [undefined, undefined];
try {
result[1] = fn();
} catch (err) {
Expand All @@ -19,7 +19,7 @@ export async function noTryAsync<T, E = Error>(
fn: () => Promise<T>,
handleErr: (error: E) => void = noop,
): Promise<NoTryResult<T, E>> {
const result: NoTryResult<T, E> = [null, null];
const result: NoTryResult<T, E> = [undefined, undefined];
try {
result[1] = await fn();
} catch (err) {
Expand Down

0 comments on commit 9c71c95

Please sign in to comment.