Skip to content

Commit

Permalink
feat: narrow down Result type after isOk or isErr
Browse files Browse the repository at this point in the history
  • Loading branch information
yifanwww committed Apr 14, 2024
1 parent a8e4b3c commit 01058c2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class RustlikeResult<T, E> implements Result<T, E> {
*
* ref: https://doc.rust-lang.org/std/result/enum.Result.html#method.is_ok
*/
isOk(): boolean {
isOk(): this is Result<T, never> {
return this._type === 'ok';
}

Expand Down Expand Up @@ -125,7 +125,7 @@ export class RustlikeResult<T, E> implements Result<T, E> {
*
* ref: https://doc.rust-lang.org/std/result/enum.Result.html#method.is_err
*/
isErr(): boolean {
isErr(): this is Result<never, E> {
return this._type === 'err';
}

Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface Result<T, E> {
*
* ref: https://doc.rust-lang.org/std/result/enum.Result.html#method.is_ok
*/
isOk(): boolean;
isOk(): this is Result<T, never>;

/**
* Returns `true` if the result is `Ok` and the value inside of it matches a predicate.
Expand Down Expand Up @@ -91,7 +91,7 @@ export interface Result<T, E> {
*
* ref: https://doc.rust-lang.org/std/result/enum.Result.html#method.is_err
*/
isErr(): boolean;
isErr(): this is Result<never, E>;

/**
* Returns `true` if the result is `Err` and the value inside of it matches a predicate.
Expand Down

0 comments on commit 01058c2

Please sign in to comment.