go-go-try 7.1.0 → 7.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/AGENTS.md ADDED
@@ -0,0 +1,182 @@
1
+ # go-go-try - Agent Guide
2
+
3
+ ## Project Overview
4
+
5
+ **go-go-try** is a TypeScript utility library for error handling inspired by Go's error handling pattern. It provides a functional approach to try/catch operations by returning a tuple `[error, value]` instead of throwing exceptions.
6
+
7
+ - **Name**: go-go-try
8
+ - **Version**: 6.2.0
9
+ - **License**: MIT
10
+ - **Repository**: thelinuxlich/go-go-try
11
+ - **Node.js Requirements**: >= 16
12
+
13
+ ## Technology Stack
14
+
15
+ - **Language**: TypeScript 5.8.3
16
+ - **Build Tool**: [pkgroll](https://github.com/privatenumber/pkgroll) - A zero-config TypeScript package bundler
17
+ - **Linter**: [Biome](https://biomejs.dev/) - Fast linter and formatter
18
+ - **Test Framework**: [Vitest](https://vitest.dev/) - Vite-native unit test framework
19
+ - **Type Testing**: [@ark/attest](https://github.com/arktypeio/arktype) - Runtime type assertions for TypeScript
20
+
21
+ ## Project Structure
22
+
23
+ ```
24
+ .
25
+ ├── src/
26
+ │ ├── index.ts # Main source file - exports goTry, goTryRaw, and utility types
27
+ │ └── index.test.ts # Comprehensive test suite with runtime and type tests
28
+ ├── dist/ # Build output (generated by pkgroll)
29
+ │ ├── index.cjs # CommonJS build
30
+ │ ├── index.mjs # ES Module build
31
+ │ ├── index.d.cts # CommonJS type definitions
32
+ │ └── index.d.mts # ES Module type definitions
33
+ ├── .github/workflows/
34
+ │ └── main.yml # CI configuration for GitHub Actions
35
+ ├── .attest/ # Ark attest cache directory
36
+ ├── package.json # Package configuration with dual CJS/ESM exports
37
+ ├── tsconfig.json # TypeScript strict configuration
38
+ ├── vitest.config.ts # Vitest configuration with type checking enabled
39
+ ├── setupVitest.ts # Vitest global setup for @ark/attest
40
+ └── README.md # User-facing documentation
41
+ ```
42
+
43
+ ## Build and Test Commands
44
+
45
+ ```bash
46
+ # Build the project (generates dist/ with CJS, ESM, and type definitions)
47
+ npm run build
48
+
49
+ # Run linting with auto-fix
50
+ npm run lint
51
+
52
+ # Run the full test suite (build + lint + vitest)
53
+ npm test
54
+ ```
55
+
56
+ The test script is a composite that:
57
+ 1. Builds the project
58
+ 2. Runs the linter
59
+ 3. Executes Vitest tests
60
+
61
+ ## Code Style Guidelines
62
+
63
+ - **Linter**: Biome is used for linting and formatting
64
+ - **Configuration**: Uses Biome's default configuration (no biome.json present)
65
+ - **Strict TypeScript**: The `tsconfig.json` enforces strict mode with additional checks:
66
+ - `noUnusedLocals`: true
67
+ - `noUnusedParameters`: true
68
+ - `allowUnreachableCode`: false
69
+ - `noUncheckedIndexedAccess`: true
70
+ - `noFallthroughCasesInSwitch`: true
71
+ - `forceConsistentCasingInFileNames`: true
72
+
73
+ ## Testing Instructions
74
+
75
+ ### Test Structure
76
+
77
+ Tests are co-located with source code in `src/index.test.ts` using Vitest.
78
+
79
+ ### Test Types
80
+
81
+ 1. **Runtime Tests**: Standard unit tests verifying behavior
82
+ 2. **Type Tests**: Using `@ark/attest` to verify TypeScript type inference at runtime
83
+
84
+ ### Key Testing Patterns
85
+
86
+ ```typescript
87
+ // Runtime test
88
+ import { assert, test } from 'vitest'
89
+ test('description', () => {
90
+ const result = goTry(() => 'value')
91
+ assert.equal(result[1], 'value')
92
+ })
93
+
94
+ // Type test
95
+ import { attest } from '@ark/attest'
96
+ test('types are correct', () => {
97
+ const result = goTry('value')
98
+ attest<Result<string, string>>(result)
99
+ })
100
+ ```
101
+
102
+ ### Running Tests
103
+
104
+ ```bash
105
+ # Run all tests with type checking
106
+ npx vitest run
107
+
108
+ # Run tests in watch mode (during development)
109
+ npx vitest
110
+ ```
111
+
112
+ ### Global Setup
113
+
114
+ The `setupVitest.ts` file configures `@ark/attest` for type assertions in tests.
115
+
116
+ ## API Design
117
+
118
+ ### Core Functions
119
+
120
+ - **`goTry<T>(value)`**: Returns `[string | undefined, T | undefined]` - error is the message string
121
+ - **`goTryRaw<T, E>(value)`**: Returns `[E | undefined, T | undefined]` - error is the raw Error object
122
+
123
+ ### Type Helpers
124
+
125
+ - **`Result<E, T>`**: The tuple type `[E | undefined, T | undefined]`
126
+ - **`Success<T>`**: `[undefined, T]`
127
+ - **`Failure<E>`**: `[E, undefined]`
128
+ - **`isSuccess(result)`**: Type guard to check if result is success
129
+ - **`isFailure(result)`**: Type guard to check if result is failure
130
+
131
+ ### Input Handling
132
+
133
+ Both functions accept:
134
+ - Direct values
135
+ - Functions (sync or async)
136
+ - Promises
137
+
138
+ ## Dual Package Support
139
+
140
+ The package supports both CommonJS and ESM consumers:
141
+
142
+ ```json
143
+ {
144
+ "main": "./dist/index.cjs",
145
+ "module": "./dist/index.mjs",
146
+ "types": "./dist/index.d.mts",
147
+ "exports": {
148
+ "require": { "types": "./dist/index.d.cts", "default": "./dist/index.cjs" },
149
+ "import": { "types": "./dist/index.d.mts", "default": "./dist/index.mjs" }
150
+ }
151
+ }
152
+ ```
153
+
154
+ ## CI/CD
155
+
156
+ GitHub Actions workflow (`.github/workflows/main.yml`) runs on every push and PR:
157
+
158
+ - Tests against Node.js versions: 12, 14, 16, 18
159
+ - Uses `yarn install` and `yarn test`
160
+ - `fail-fast: false` to see results for all Node versions
161
+
162
+ ## Security Considerations
163
+
164
+ - Zero runtime dependencies - reduces supply chain attack surface
165
+ - Dev dependencies are locked via `package-lock.json`
166
+ - Uses `type: "module"` for native ESM support
167
+
168
+ ## Development Workflow
169
+
170
+ 1. Make changes to `src/index.ts`
171
+ 2. Add/update tests in `src/index.test.ts`
172
+ 3. Run `npm test` to verify build, lint, and tests pass
173
+ 4. The CI will test against multiple Node.js versions on push
174
+
175
+ ## Notes for AI Agents
176
+
177
+ - Always run `npm test` after making changes to ensure build, lint, and tests pass
178
+ - Type tests with `@ark/attest` are as important as runtime tests
179
+ - The library has zero dependencies - avoid adding any
180
+ - Maintain dual CJS/ESM compatibility when making changes
181
+ - Follow the existing function overload patterns for type inference
182
+ - Error handling should preserve the Go-style tuple return pattern
package/README.md CHANGED
@@ -202,6 +202,88 @@ if (err === undefined) {
202
202
  }
203
203
  ```
204
204
 
205
+ ### Tagged Errors for Discriminated Unions
206
+
207
+ Create typed errors with a `_tag` property for pattern matching and discriminated unions:
208
+
209
+ ```ts
210
+ import { taggedError, goTryRaw, failure, type Result } from 'go-go-try'
211
+
212
+ // Define error types
213
+ const DatabaseError = taggedError('DatabaseError')
214
+ const NetworkError = taggedError('NetworkError')
215
+ const ValidationError = taggedError('ValidationError')
216
+
217
+ // Create a union type
218
+ import type { TaggedUnion } from 'go-go-try'
219
+
220
+ // Option 1: Using TaggedUnion helper (cleaner)
221
+ const DatabaseError = taggedError('DatabaseError')
222
+ const NetworkError = taggedError('NetworkError')
223
+ const ValidationError = taggedError('ValidationError')
224
+
225
+ type AppError = TaggedUnion<[typeof DatabaseError, typeof NetworkError, typeof ValidationError]>
226
+ // Equivalent to: DatabaseError | NetworkError | ValidationError
227
+
228
+ // Option 2: Using InstanceType (standard TypeScript)
229
+ type AppErrorVerbose =
230
+ | InstanceType<typeof DatabaseError>
231
+ | InstanceType<typeof NetworkError>
232
+ | InstanceType<typeof ValidationError>
233
+
234
+ // Use in functions with typed error returns
235
+ async function fetchUser(id: string): Promise<Result<AppError, User>> {
236
+ const [dbErr, user] = await goTryRaw(queryDatabase(id), DatabaseError)
237
+ if (dbErr) return failure(dbErr)
238
+
239
+ const [netErr, enriched] = await goTryRaw(enrichUserData(user!), NetworkError)
240
+ if (netErr) return failure(netErr)
241
+
242
+ return [undefined, enriched] as const
243
+ }
244
+
245
+ // Pattern matching on errors
246
+ const [err, user] = await fetchUser('123')
247
+ if (err) {
248
+ switch (err._tag) {
249
+ case 'DatabaseError':
250
+ console.error('Database failed:', err.message)
251
+ break
252
+ case 'NetworkError':
253
+ console.error('Network issue:', err.message)
254
+ break
255
+ case 'ValidationError':
256
+ console.error('Invalid data:', err.message)
257
+ break
258
+ }
259
+ }
260
+
261
+ // Exhaustive switch with compile-time safety
262
+ function assertNever(value: never): never {
263
+ throw new Error(`Unhandled case: ${String(value)}`)
264
+ }
265
+
266
+ function handleError(err: AppError): string {
267
+ switch (err._tag) {
268
+ case 'DatabaseError':
269
+ return `DB: ${err.message}`
270
+ case 'NetworkError':
271
+ return `NET: ${err.message}`
272
+ case 'ValidationError':
273
+ return `VAL: ${err.message}`
274
+ default:
275
+ // TypeScript will error here if any case is missing above
276
+ return assertNever(err)
277
+ }
278
+ }
279
+ ```
280
+
281
+ The `taggedError` function creates an error class with:
282
+ - `_tag`: A readonly string literal for discriminated unions
283
+ - `message`: The error message
284
+ - `cause`: Optional cause for error chaining
285
+ - `name`: Set to the tag value
286
+
205
287
  ### Helper Functions
206
288
 
207
289
  Build custom utilities on top of the primitives:
@@ -236,12 +318,32 @@ Executes a function, promise, or value and returns a Result type with error mess
236
318
  function goTry<T>(value: T | Promise<T> | (() => T | Promise<T>)): Result<string, T> | Promise<Result<string, T>>
237
319
  ```
238
320
 
239
- ### `goTryRaw<T, E>(value)`
321
+ ### `goTryRaw<T, E>(value, ErrorClass?)`
240
322
 
241
323
  Like `goTry` but returns the raw Error object instead of just the message.
242
324
 
325
+ Optionally accepts an error constructor to wrap caught errors - useful with `taggedError` for discriminated unions.
326
+
243
327
  ```ts
328
+ // Without ErrorClass - err is Error | undefined
244
329
  function goTryRaw<T, E = Error>(value: T | Promise<T> | (() => T | Promise<T>)): Result<E, T> | Promise<Result<E, T>>
330
+
331
+ // With ErrorClass - err is E | undefined (e.g., DatabaseError | undefined)
332
+ function goTryRaw<T, E>(value: T | Promise<T> | (() => T | Promise<T>), ErrorClass: ErrorConstructor<E>): Result<E, T> | Promise<Result<E, T>>
333
+ ```
334
+
335
+ **Example:**
336
+ ```ts
337
+ const DatabaseError = taggedError('DatabaseError')
338
+
339
+ // Raw error (default)
340
+ const [err1, data1] = await goTryRaw(fetchData())
341
+ // err1 is Error | undefined
342
+
343
+ // Tagged error
344
+ const [err2, data2] = await goTryRaw(fetchData(), DatabaseError)
345
+ // err2 is DatabaseError | undefined
346
+ // err2._tag is 'DatabaseError' - enables discriminated unions
245
347
  ```
246
348
 
247
349
  ### `goTryAll<T>(items, options?)`
@@ -325,12 +427,104 @@ function success<T>(value: T): Success<T>
325
427
  function failure<E>(error: E): Failure<E>
326
428
  ```
327
429
 
430
+ ### `taggedError<T>(tag)`
431
+
432
+ Creates a tagged error class for discriminated error handling. Returns a class constructor that extends `Error` and includes a readonly `_tag` property.
433
+
434
+ ```ts
435
+ function taggedError<T extends string>(tag: T): TaggedErrorClass<T>
436
+
437
+ // Returned class interface:
438
+ class TaggedErrorClass<T> extends Error implements TaggedError<T> {
439
+ readonly _tag: T
440
+ readonly cause?: unknown
441
+ constructor(message: string, options?: { cause?: unknown })
442
+ }
443
+ ```
444
+
445
+ **Example:**
446
+ ```ts
447
+ const DatabaseError = taggedError('DatabaseError')
448
+ const err = new DatabaseError('connection failed', { cause: originalError })
449
+
450
+ console.log(err._tag) // 'DatabaseError'
451
+ console.log(err.message) // 'connection failed'
452
+ console.log(err.name) // 'DatabaseError'
453
+ console.log(err.cause) // originalError
454
+ ```
455
+
456
+ ### `TaggedUnion<T>`
457
+
458
+ Creates a union type from multiple tagged error classes.
459
+
460
+ ```ts
461
+ type TaggedUnion<T extends readonly ErrorConstructor<unknown>[]> =
462
+ { [K in keyof T]: T[K] extends ErrorConstructor<infer E> ? E : never }[number]
463
+ ```
464
+
465
+ **Example:**
466
+ ```ts
467
+ const DatabaseError = taggedError('DatabaseError')
468
+ const NetworkError = taggedError('NetworkError')
469
+ const ValidationError = taggedError('ValidationError')
470
+
471
+ // Before (verbose):
472
+ type AppErrorVerbose =
473
+ | InstanceType<typeof DatabaseError>
474
+ | InstanceType<typeof NetworkError>
475
+ | InstanceType<typeof ValidationError>
476
+
477
+ // After (clean):
478
+ type AppError = TaggedUnion<[typeof DatabaseError, typeof NetworkError, typeof ValidationError]>
479
+ // Results in: DatabaseError | NetworkError | ValidationError
480
+ ```
481
+
482
+ #### Automatic Union Inference
483
+
484
+ When using `goTryRaw` with different error classes in the same function, TypeScript **automatically infers** the union type without needing explicit type annotations:
485
+
486
+ ```ts
487
+ // No explicit return type needed!
488
+ async function fetchUserData(id: string) {
489
+ // First operation might fail with DatabaseError
490
+ const [dbErr, user] = await goTryRaw(queryDb(id), DatabaseError)
491
+ if (dbErr) return failure(dbErr) // returns Failure<DatabaseError>
492
+
493
+ // Second operation might fail with NetworkError
494
+ const [netErr, enriched] = await goTryRaw(enrichUser(user!), NetworkError)
495
+ if (netErr) return failure(netErr) // returns Failure<NetworkError>
496
+
497
+ return success(enriched) // returns Success<User>
498
+ }
499
+
500
+ // TypeScript infers: Promise<Result<DatabaseError | NetworkError, User>>
501
+ // No TaggedUnion or explicit types needed!
502
+ ```
503
+
504
+ The inferred union enables exhaustive pattern matching:
505
+
506
+ ```ts
507
+ const [err, user] = await fetchUserData('123')
508
+ if (err) {
509
+ switch (err._tag) {
510
+ case 'DatabaseError': /* handle db error */ break
511
+ case 'NetworkError': /* handle network error */ break
512
+ default: assertNever(err) // compile-time safety
513
+ }
514
+ }
515
+ ```
516
+
328
517
  ## Types
329
518
 
330
519
  ```ts
331
520
  type Success<T> = readonly [undefined, T]
332
521
  type Failure<E> = readonly [E, undefined]
333
522
  type Result<E, T> = Success<T> | Failure<E>
523
+
524
+ // Error type helpers
525
+ type TaggedInstance<T> = T extends ErrorConstructor<infer E> ? E : never
526
+ type TaggedUnion<T extends readonly ErrorConstructor<unknown>[]> =
527
+ { [K in keyof T]: T[K] extends ErrorConstructor<infer E> ? E : never }[number]
334
528
  ```
335
529
 
336
530
  ## License
package/dist/index.cjs CHANGED
@@ -1,5 +1,15 @@
1
1
  'use strict';
2
2
 
3
+ function taggedError(tag) {
4
+ return class TaggedErrorClass extends Error {
5
+ constructor(message, options) {
6
+ super(message);
7
+ this._tag = tag;
8
+ this.name = tag;
9
+ this.cause = options?.cause;
10
+ }
11
+ };
12
+ }
3
13
  function isSuccess(result) {
4
14
  return result[0] === void 0;
5
15
  }
@@ -118,24 +128,30 @@ function goTry(value) {
118
128
  return failure(getErrorMessage(err));
119
129
  }
120
130
  }
121
- function goTryRaw(value) {
131
+ function goTryRaw(value, ErrorClass) {
132
+ const wrapError = (err) => {
133
+ if (ErrorClass) {
134
+ if (err === void 0) {
135
+ return new ErrorClass("undefined");
136
+ }
137
+ if (isError(err)) {
138
+ return new ErrorClass(err.message, { cause: err });
139
+ }
140
+ return new ErrorClass(String(err));
141
+ }
142
+ if (err === void 0) {
143
+ return new Error("undefined");
144
+ }
145
+ return isError(err) ? err : new Error(String(err));
146
+ };
122
147
  try {
123
148
  const result = typeof value === "function" ? value() : value;
124
149
  if (isPromise(result)) {
125
- return result.then((resolvedValue) => success(resolvedValue)).catch((err) => {
126
- if (err === void 0) {
127
- return failure(new Error("undefined"));
128
- }
129
- return failure(
130
- isError(err) ? err : new Error(String(err))
131
- );
132
- });
150
+ return result.then((resolvedValue) => success(resolvedValue)).catch((err) => failure(wrapError(err)));
133
151
  }
134
152
  return success(result);
135
153
  } catch (err) {
136
- return failure(
137
- isError(err) ? err : new Error(String(err))
138
- );
154
+ return failure(wrapError(err));
139
155
  }
140
156
  }
141
157
 
@@ -148,3 +164,4 @@ exports.goTryRaw = goTryRaw;
148
164
  exports.isFailure = isFailure;
149
165
  exports.isSuccess = isSuccess;
150
166
  exports.success = success;
167
+ exports.taggedError = taggedError;
package/dist/index.d.cts CHANGED
@@ -1,6 +1,51 @@
1
1
  type Success<T> = readonly [undefined, T];
2
2
  type Failure<E> = readonly [E, undefined];
3
3
  type Result<E, T> = Success<T> | Failure<E>;
4
+ /**
5
+ * Base interface for tagged errors.
6
+ * The `_tag` property enables discriminated union narrowing.
7
+ */
8
+ interface TaggedError<T extends string> {
9
+ readonly _tag: T;
10
+ readonly message: string;
11
+ readonly cause?: unknown;
12
+ }
13
+ /**
14
+ * Creates a tagged error class for discriminated error handling.
15
+ *
16
+ * @template T The literal type of the tag
17
+ * @param tag The string tag to identify this error type (e.g., 'DatabaseError')
18
+ * @returns A class constructor for creating tagged errors
19
+ *
20
+ * @example
21
+ * const DatabaseError = taggedError('DatabaseError')
22
+ * const NetworkError = taggedError('NetworkError')
23
+ *
24
+ * type MyError = InstanceType<typeof DatabaseError> | InstanceType<typeof NetworkError>
25
+ *
26
+ * function fetchUser(id: string): Result<MyError, User> {
27
+ * const [err, user] = goTryRaw(fetch(`/users/${id}`), DatabaseError)
28
+ * if (err) return failure(err)
29
+ * // ...
30
+ * }
31
+ *
32
+ * // Pattern matching on errors
33
+ * if (err._tag === 'DatabaseError') {
34
+ * // TypeScript knows this is DatabaseError
35
+ * }
36
+ */
37
+ declare function taggedError<T extends string>(tag: T): {
38
+ new (message: string, options?: {
39
+ cause?: unknown;
40
+ }): {
41
+ readonly _tag: T;
42
+ readonly cause?: unknown;
43
+ name: string;
44
+ message: string;
45
+ stack?: string;
46
+ };
47
+ isError(error: unknown): error is Error;
48
+ };
4
49
  type ResultWithDefault<E, T> = readonly [E | undefined, T];
5
50
  type MaybePromise<T> = T | Promise<T>;
6
51
  interface GoTryAllOptions {
@@ -121,6 +166,28 @@ declare function goTry<T>(fn: () => Promise<T>): Promise<Result<string, T>>;
121
166
  declare function goTry<T>(promise: Promise<T>): Promise<Result<string, T>>;
122
167
  declare function goTry<T>(fn: () => T): Result<string, T>;
123
168
  declare function goTry<T>(value: T): Result<string, T>;
169
+ /**
170
+ * Type for error constructors that can be used with goTryRaw.
171
+ */
172
+ type ErrorConstructor<E> = new (message: string, options?: {
173
+ cause?: unknown;
174
+ }) => E;
175
+ /**
176
+ * Creates a union type from multiple tagged error classes.
177
+ *
178
+ * @template T A tuple of tagged error class types
179
+ * @returns A union of all instance types
180
+ *
181
+ * @example
182
+ * const DatabaseError = taggedError('DatabaseError')
183
+ * const NetworkError = taggedError('NetworkError')
184
+ *
185
+ * type AppError = TaggedUnion<[typeof DatabaseError, typeof NetworkError]>
186
+ * // Equivalent to: DatabaseError | NetworkError
187
+ */
188
+ type TaggedUnion<T extends readonly ErrorConstructor<unknown>[]> = {
189
+ [K in keyof T]: T[K] extends ErrorConstructor<infer E> ? E : never;
190
+ }[number];
124
191
  /**
125
192
  * Executes a function, promise, or value and returns a Result type.
126
193
  * If an error occurs, it returns a Failure with the raw error object.
@@ -128,6 +195,7 @@ declare function goTry<T>(value: T): Result<string, T>;
128
195
  * @template T The type of the successful result
129
196
  * @template E The type of the error, defaults to Error
130
197
  * @param {T | Promise<T> | (() => T | Promise<T>)} value - The value, promise, or function to execute
198
+ * @param {ErrorConstructor<E>} [ErrorClass] - Optional error constructor to wrap caught errors
131
199
  * @returns {Result<E, T> | Promise<Result<E, T>>} A Result type or a Promise of a Result type
132
200
  *
133
201
  * @example
@@ -141,13 +209,24 @@ declare function goTry<T>(value: T): Result<string, T>;
141
209
  * @example
142
210
  * // With a promise
143
211
  * const [err, result] = await goTryRaw(fetch('https://api.example.com/data'));
212
+ *
213
+ * @example
214
+ * // With tagged error for discriminated unions
215
+ * const DatabaseError = taggedError('DatabaseError');
216
+ * const [err, result] = await goTryRaw(fetchData(), DatabaseError);
217
+ * // err is InstanceType<typeof DatabaseError> | undefined
144
218
  */
145
219
  declare function goTryRaw<T, E = Error>(fn: () => never): Result<E, never>;
220
+ declare function goTryRaw<T, E = Error>(fn: () => never, ErrorClass: ErrorConstructor<E>): Result<E, never>;
146
221
  declare function goTryRaw<T, E = Error>(fn: () => Promise<T>): Promise<Result<E, T>>;
222
+ declare function goTryRaw<T, E = Error>(fn: () => Promise<T>, ErrorClass: ErrorConstructor<E>): Promise<Result<E, T>>;
147
223
  declare function goTryRaw<T, E = Error>(promise: Promise<T>): Promise<Result<E, T>>;
224
+ declare function goTryRaw<T, E = Error>(promise: Promise<T>, ErrorClass: ErrorConstructor<E>): Promise<Result<E, T>>;
148
225
  declare function goTryRaw<T, E = Error>(fn: () => T): Result<E, T>;
226
+ declare function goTryRaw<T, E = Error>(fn: () => T, ErrorClass: ErrorConstructor<E>): Result<E, T>;
149
227
  declare function goTryRaw<T, E = Error>(value: T): Result<E, T>;
228
+ declare function goTryRaw<T, E = Error>(value: T, ErrorClass: ErrorConstructor<E>): Result<E, T>;
150
229
 
151
- export { failure, goTry, goTryAll, goTryAllRaw, goTryOr, goTryRaw, isFailure, isSuccess, success };
152
- export type { Failure, GoTryAllOptions, MaybePromise, Result, ResultWithDefault, Success };
230
+ export { failure, goTry, goTryAll, goTryAllRaw, goTryOr, goTryRaw, isFailure, isSuccess, success, taggedError };
231
+ export type { ErrorConstructor, Failure, GoTryAllOptions, MaybePromise, Result, ResultWithDefault, Success, TaggedError, TaggedUnion };
153
232
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sources":["../src/index.ts"],"mappings":"KAAY,OAAO,CAAC,CAAC,IAAI,SAAS,CAAC,SAAS,EAAE,CAAC,CAAC,CAAA;KACpC,OAAO,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,CAAA;KACpC,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;KAEtC,iBAAiB,CAAC,CAAC,EAAE,CAAC,IAAI,SAAS,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,CAAC,CAAA;KAErD,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;UAE3B,eAAe;IAC9B;AAFF;AACA;OAIK;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;iBAEe,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,CAE1E;iBACe,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,IAAI,OAAO,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