Skip to content

Commit

Permalink
feat: [类型] 函数返回结果 (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
iugo authored May 23, 2024
1 parent d4e4c34 commit 78a9b42
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ts/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,12 @@ export function assertError(v: unknown): asserts v is Error {
throw new TypeError(`should be Error but ${v}`);
}
}

/**
* [类型] 函数返回结果
*
* @description 可能出现错误的结果 (类似 Rust Result)
*/
export type Result<T, E extends Error = Error, L extends boolean = true> =
L extends true ? [E, null] | [true, null] | [null, T]
: [E, null] | [null, T];

0 comments on commit 78a9b42

Please sign in to comment.