Skip to content

Commit

Permalink
Some value as NonNullable
Browse files Browse the repository at this point in the history
  • Loading branch information
jarvisjiang committed May 8, 2024
1 parent 63e5f75 commit 69e14e1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/enum/option.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* @fileoverview 仿rust的[Option](https://doc.rust-lang.org/core/option/index.html)枚举,
* 用于替代null和undefined的使用。
* @fileoverview A Rust-inspired [Option](https://doc.rust-lang.org/core/option/index.html) enum, used as an alternative to the use of null and undefined.
*/

/**
Expand Down Expand Up @@ -29,7 +28,7 @@ interface None {
export type Option<T> = Some<T> | None;

/**
* 创建一个`Some`对象
* Create a `Some` object.
*
* # Examples
*
Expand All @@ -38,10 +37,10 @@ export type Option<T> = Some<T> | None;
* console.assert(v.unwrap() === 10);
* ```
*
* @param value 被包裹的值,不能为null和undefined
* @param value The wrapped value which can not be null or undefined.
* @returns {Some}
*/
export function Some<T>(value: T): Option<T> {
export function Some<T>(value: NonNullable<T>): Option<T> {
if (value == null) {
throw new TypeError('Some value can not be null or undefined');
}
Expand All @@ -55,7 +54,8 @@ export function Some<T>(value: T): Option<T> {
}

/**
* `None`值是固定的
* `None` value is freeze.
*
* @constant {None}
*/
export const None: None = {
Expand Down
12 changes: 5 additions & 7 deletions src/enum/result.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/**
* @fileoverview 仿rust的[Result](https://doc.rust-lang.org/core/result/index.html)枚举,
* 用于错误处理。
* @fileoverview A Rust-inspired [Result](https://doc.rust-lang.org/core/result/index.html) enum, used for better error handling.
*/


/**
* result::Ok type
*/
Expand Down Expand Up @@ -32,7 +30,7 @@ interface Err<T, E> {
export type Result<T, E> = Ok<T, E> | Err<T, E>;

/**
* 创建一个`Ok`对象
* Create an `Ok` object.
*
* # Examples
*
Expand Down Expand Up @@ -65,7 +63,7 @@ if (res.isNone()) {
*
* ```
*
* @param value 被包裹的值
* @param value The wrapped value.
* @returns {Ok}
*/
export function Ok<T, E>(value: T): Result<T, E> {
Expand All @@ -81,7 +79,7 @@ export function Ok<T, E>(value: T): Result<T, E> {
}

/**
* 创建一个`Err`对象
* Create an `Err` object.
*
* # Examples
*
Expand All @@ -90,7 +88,7 @@ export function Ok<T, E>(value: T): Result<T, E> {
* console.assert(e.err().message === 'unknown error');
* ```
*
* @param error 被包裹的错误
* @param error The wrapped error value.
* @returns {Err}
*/
export function Err<T, E>(error: E): Result<T, E> {
Expand Down

0 comments on commit 69e14e1

Please sign in to comment.