Skip to content

Commit

Permalink
Fix isErr for unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
alexshelkov committed Jan 24, 2022
1 parent 762b1d0 commit 15c65c5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -8,7 +8,7 @@
"error",
"error-handling"
],
"version": "1.0.21",
"version": "1.0.22",
"author": "Alex Shelkovskiy <alexshelkov@gmail.com>",
"repository": "https://github.com/alexshelkov/result",
"license": "MIT",
Expand Down
8 changes: 3 additions & 5 deletions src/checks.ts
@@ -1,14 +1,12 @@
import { Err } from './err';
import { Failure, Success } from './result';

export const isUnknownErr = (input: unknown): input is Err => {
export const isErr = <Error = Err>(
input: Error | unknown
): input is Error extends Err ? Error : never => {
return typeof input === 'object' && input !== null && 'type' in input;
};

export const isErr = <Error = Err>(input: Error): input is Error extends Err ? Error : never => {
return isUnknownErr(input);
};

export const isErrType = <
Type extends string,
Fail,
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Expand Up @@ -2,7 +2,7 @@ export { ErrUtil as Err, Err as ErrInfo, ErrLevel, Errs } from './err';

export { Success, Failure, Result, Response } from './result';

export { isUnknownErr, isErr, isErrType, isSuccessLike, isFailureLike } from './checks';
export { isErr, isErrType, isSuccessLike, isFailureLike } from './checks';

export {
ok,
Expand Down
11 changes: 2 additions & 9 deletions src/utils.ts
Expand Up @@ -9,14 +9,7 @@ import {
Response,
} from './result';

import {
isPromise,
isHaveStatus,
isSuccessLike,
isFailureLike,
isErr,
isUnknownErr,
} from './checks';
import { isPromise, isHaveStatus, isSuccessLike, isFailureLike, isErr } from './checks';

import { Err, ErrUtil } from './err';

Expand Down Expand Up @@ -63,7 +56,7 @@ const maybeFailToResult = <Data, Fail>(
prevResult.message,
prevResult.code
);
} else if (isUnknownErr(result)) {
} else if (isErr(result)) {
exception = new FailureException(
result.type,
result as unknown as Fail,
Expand Down

0 comments on commit 15c65c5

Please sign in to comment.