Skip to content

Commit

Permalink
feat: Optional type is no longer exported
Browse files Browse the repository at this point in the history
  • Loading branch information
yifanwww committed Mar 3, 2024
1 parent 9ee8c28 commit 42a6fd8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/json/serializr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { AdditionalPropArgs, ModelSchema, PropDeserializer, PropSchema, Pro

import { Err, Ok } from '../factory';
import { RustlikeResult } from '../result';
import type { Optional, Result } from '../types';
import type { ResultType } from '../types.internal';
import type { Result } from '../types';
import type { Optional, ResultType } from '../types.internal';

import type { ResultJson } from './types';

Expand Down
4 changes: 2 additions & 2 deletions src/result.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Optional, Result } from './types';
import type { ResultType } from './types.internal';
import type { Result } from './types';
import type { Optional, ResultType } from './types.internal';

/**
* The default implementation of interface `Result`.
Expand Down
15 changes: 15 additions & 0 deletions src/types.internal.ts
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
export type ResultType = 'ok' | 'err';

/**
* JavaScript ECMAScript 2020 contains two new proposals that can help us deal with undefined/null more easily:
* - https://github.com/tc39/proposal-optional-chaining
* - https://github.com/tc39/proposal-nullish-coalescing
*
* We don't need Rust-like Option anymore in most cases unless we want functional programming.
*
* This type doesn't use the name `Option`,
* by giving it a different name we can easily know that this is not Rust-like Option.
*
* This type is not exported since there's no convention for using `Optional` type in TypeScript world.
* People just simply write `T | undefined`.
*/
export type Optional<T> = T | undefined;
12 changes: 1 addition & 11 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
/**
* JavaScript ECMAScript 2020 contains two new proposals that can help us deal with undefined/null more easily:
* - https://github.com/tc39/proposal-optional-chaining
* - https://github.com/tc39/proposal-nullish-coalescing
*
* We don't need Rust-like Option anymore in most cases unless we want functional programming.
*
* This type doesn't use the name `Option`,
* by giving it a different name we can easily know that this is not Rust-like Option.
*/
export type Optional<T> = T | undefined;
import type { Optional } from './types.internal';

/**
* The interface of `Result` that defines the methods that `Result` should support.
Expand Down

0 comments on commit 42a6fd8

Please sign in to comment.