Skip to content

Commit e07b30c

Browse files
committed
separates result creation into own factory class
1 parent 26c623c commit e07b30c

File tree

6 files changed

+83
-86
lines changed

6 files changed

+83
-86
lines changed

biome.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"noExplicitAny": "off"
1616
},
1717
"complexity": {
18-
"noBannedTypes": "off"
18+
"noBannedTypes": "off",
19+
"noStaticOnlyClass": "off"
1920
},
2021
"correctness": {
2122
"useYield": "off"

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"private": false,
33
"name": "typescript-result",
4-
"version": "3.4.0-beta.1",
5-
"description": "A Result type inspired by Rust and Kotlin that leverages TypeScript's powerful type system to simplify error handling and make your code more readable and maintainable.",
4+
"version": "3.4.0-beta.2",
5+
"description": "Supercharge your TypeScript error handling with a powerful Result type that transforms chaotic try-catch blocks into elegant, type-safe code.",
66
"keywords": [
77
"result",
88
"type",
@@ -13,7 +13,9 @@
1313
"exception",
1414
"ok",
1515
"success",
16-
"failure"
16+
"failure",
17+
"Rust",
18+
"functional programming"
1719
],
1820
"author": {
1921
"name": "Erik Verweij",

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,7 @@ Creates a new result instance that represents a successful outcome.
14211421

14221422
#### Example
14231423
```ts
1424-
const result = Result.ok(42); // Result<number, never>
1424+
const result = Result.ok(42); // Result.Ok<number>
14251425
```
14261426

14271427
### Result.error(error)
@@ -1436,7 +1436,7 @@ Creates a new result instance that represents a failed outcome.
14361436

14371437
#### Example
14381438
```ts
1439-
const result = Result.error(new NotFoundError()); // Result<never, NotFoundError>
1439+
const result = Result.error(new NotFoundError()); // Result.Error<NotFoundError>
14401440
```
14411441

14421442
### Result.isResult(possibleResult)

src/index.ts

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
type IfGeneratorAsync,
66
type InferGeneratorError,
77
type InferGeneratorReturn,
8-
Result as ResultBase,
8+
type Result as ResultBase,
9+
ResultFactory,
910
} from "./result.js";
1011

1112
export { AsyncResult } from "./result.js";
@@ -36,38 +37,4 @@ export type Result<Value, Err> =
3637
| ([Value] extends [never] ? never : Result.Ok<Value>)
3738
| ([Err] extends [never] ? never : Result.Error<Err>);
3839

39-
export const Result: {
40-
ok: typeof ResultBase.ok;
41-
error: typeof ResultBase.error;
42-
assertOk: typeof ResultBase.assertOk;
43-
assertError: typeof ResultBase.assertError;
44-
isResult: typeof ResultBase.isResult;
45-
isAsyncResult: typeof ResultBase.isAsyncResult;
46-
all: typeof ResultBase.all;
47-
allCatching: typeof ResultBase.allCatching;
48-
wrap: typeof ResultBase.wrap;
49-
try: typeof ResultBase.try;
50-
fromAsync: typeof ResultBase.fromAsync;
51-
fromAsyncCatching: typeof ResultBase.fromAsyncCatching;
52-
gen: typeof ResultBase.gen;
53-
genCatching: typeof ResultBase.genCatching;
54-
[Symbol.hasInstance]: (instance: unknown) => boolean;
55-
} = {
56-
ok: ResultBase.ok,
57-
error: ResultBase.error,
58-
isResult: ResultBase.isResult,
59-
isAsyncResult: ResultBase.isAsyncResult,
60-
all: ResultBase.all,
61-
allCatching: ResultBase.allCatching,
62-
wrap: ResultBase.wrap,
63-
try: ResultBase.try,
64-
fromAsync: ResultBase.fromAsync,
65-
fromAsyncCatching: ResultBase.fromAsyncCatching,
66-
gen: ResultBase.gen,
67-
genCatching: ResultBase.genCatching,
68-
assertOk: ResultBase.assertOk,
69-
assertError: ResultBase.assertError,
70-
[Symbol.hasInstance](instance: unknown) {
71-
return instance instanceof ResultBase;
72-
},
73-
};
40+
export const Result: typeof ResultFactory = ResultFactory;

src/integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it } from "vitest";
22
import { assertUnreachable } from "./helpers.js";
3-
import { Result } from "./result.js";
3+
import { Result } from "./index.js";
44

55
describe("User management app", () => {
66
let count = 0;

0 commit comments

Comments
 (0)