-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: export interface but not class
- Loading branch information
Showing
9 changed files
with
348 additions
and
310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Test fn \`Err\` should create \`Err\` result 1`] = ` | ||
RustlikeResult { | ||
"_error": "Some error message", | ||
"_type": "err", | ||
"_value": undefined, | ||
} | ||
`; | ||
|
||
exports[`Test fn \`Ok\` should create \`Ok\` result 1`] = ` | ||
RustlikeResult { | ||
"_error": undefined, | ||
"_type": "ok", | ||
"_value": 1, | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Err, Ok } from '../factory'; | ||
|
||
describe(`Test fn \`${Ok.name}\``, () => { | ||
it('should create `Ok` result', () => { | ||
expect(Ok(1)).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
describe(`Test fn \`${Err.name}\``, () => { | ||
it('should create `Err` result', () => { | ||
expect(Err('Some error message')).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { RustlikeResult } from './result.class'; | ||
import type { Result } from './result.interface'; | ||
|
||
/** | ||
* Creates a `Result` that contains the success value. | ||
*/ | ||
export function Ok<T>(value: T): Result<T, never>; | ||
/** | ||
* Creates a `Result` that contains the success value. | ||
*/ | ||
export function Ok<T, E>(value: T): Result<T, E>; | ||
export function Ok<T, E>(value: T): Result<T, E> { | ||
return RustlikeResult.Ok(value); | ||
} | ||
|
||
/** | ||
* Creates a `Result` that contains the error value. | ||
*/ | ||
export function Err<E>(error: E): Result<never, E>; | ||
/** | ||
* Creates a `Result` that contains the error value. | ||
*/ | ||
export function Err<T, E>(error: E): Result<T, E>; | ||
export function Err<T, E>(error: E): Result<T, E> { | ||
return RustlikeResult.Err(error); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './result'; | ||
export * from './factory'; | ||
export * from './result.interface'; | ||
export * from './types'; |
Oops, something went wrong.