Skip to content

Commit 15c2902

Browse files
committed
Export public helper types from hardtry/types entrypoint
1 parent f945f82 commit 15c2902

File tree

5 files changed

+56
-8
lines changed

5 files changed

+56
-8
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
```ts
1111
import * as try$ from "hardtry"
12+
import type { FlowExit, SettledResult } from "hardtry/types"
1213

1314
const result = await try$
1415
.retry(3)
@@ -276,9 +277,18 @@ From `hardtry/errors`:
276277
- `UnhandledException`
277278
- `Panic`
278279

280+
From `hardtry/types`:
281+
282+
- `AllSettledResult`
283+
- `SettledFulfilled`
284+
- `SettledRejected`
285+
- `SettledResult`
286+
- `FlowExit`
287+
279288
```ts
280289
import * as try$ from "hardtry"
281290
import { Panic, TimeoutError, UnhandledException } from "hardtry/errors"
291+
import type { FlowExit, SettledResult } from "hardtry/types"
282292
```
283293

284294
### Common signatures
@@ -296,6 +306,7 @@ import { Panic, TimeoutError, UnhandledException } from "hardtry/errors"
296306
- Timeout scope is total execution.
297307
- `retry()` and `timeout()` only compose with `run()` / `runSync()`. Use nested `run()` calls inside orchestration tasks for leaf policies.
298308
- Error classes and `PanicCode` are exported from `hardtry/errors`.
309+
- Public helper types are exported from `hardtry/types`.
299310
- `flow` requires at least one `$exit(...)` path; otherwise it throws.
300311
- Control outcomes have precedence over mapped catch results in racing scenarios.
301312
- `wrap` is only available from `try$.wrap(...)` and can be chained as `.wrap().wrap()`.

bunup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { defineConfig } from "bunup"
22

33
export default defineConfig({
44
dts: true,
5-
entry: ["src/index.ts", "src/errors.ts"],
5+
entry: ["src/index.ts", "src/errors.ts", "src/types.ts"],
66
format: "esm",
77
outDir: "dist",
88
sourcemap: true,

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
"./errors": {
3535
"types": "./dist/errors.d.ts",
3636
"import": "./dist/errors.js"
37+
},
38+
"./types": {
39+
"types": "./dist/types.d.ts",
40+
"import": "./dist/types.js"
3741
}
3842
},
3943
"scripts": {

src/__tests__/types.test.ts

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
TimeoutError,
66
UnhandledException,
77
} from "../errors"
8+
import type { FlowExit, SettledResult } from "../types"
89
import * as try$ from "../index"
910

1011
type Expect<T extends true> = T
@@ -179,9 +180,7 @@ describe("type inference", () => {
179180
Equal<typeof result, Promise<number | UnhandledException | CancellationError>>
180181
>
181182
type _assertAll = Expect<Equal<typeof allResult, Promise<{ a: 1; b: 1 }>>>
182-
type _assertSettled = Expect<
183-
Equal<typeof settledResult, Promise<{ a: try$.SettledResult<"ok"> }>>
184-
>
183+
type _assertSettled = Expect<Equal<typeof settledResult, Promise<{ a: SettledResult<"ok"> }>>>
185184
type _assertFlow = Expect<Equal<typeof flowResult, Promise<"done">>>
186185

187186
if (typecheckOnly()) {
@@ -604,6 +603,16 @@ describe("type inference", () => {
604603
})
605604

606605
describe("allSettled", () => {
606+
it("exports settled result types from the dedicated types entrypoint", () => {
607+
if (typecheckOnly()) return
608+
609+
const settled = { status: "fulfilled", value: "ok" } as const satisfies SettledResult<"ok">
610+
611+
type _assert = Expect<
612+
Equal<typeof settled, { readonly status: "fulfilled"; readonly value: "ok" }>
613+
>
614+
})
615+
607616
it("infers settled result types", () => {
608617
if (typecheckOnly()) return
609618

@@ -620,8 +629,8 @@ describe("type inference", () => {
620629
Equal<
621630
typeof result,
622631
Promise<{
623-
a: try$.SettledResult<number>
624-
b: try$.SettledResult<string>
632+
a: SettledResult<number>
633+
b: SettledResult<string>
625634
}>
626635
>
627636
>
@@ -691,6 +700,14 @@ describe("type inference", () => {
691700
})
692701

693702
describe("flow", () => {
703+
it("exports flow exit types from the dedicated types entrypoint", () => {
704+
if (typecheckOnly()) return
705+
706+
const exitValue = null as unknown as FlowExit<"done">
707+
708+
type _assert = Expect<Equal<typeof exitValue, FlowExit<"done">>>
709+
})
710+
694711
it("infers union of $exit values", () => {
695712
const result = try$.flow({
696713
a() {
@@ -756,8 +773,8 @@ describe("type inference", () => {
756773
Equal<
757774
typeof result,
758775
Promise<{
759-
a: try$.SettledResult<1>
760-
b: try$.SettledResult<"ok">
776+
a: SettledResult<1>
777+
b: SettledResult<"ok">
761778
}>
762779
>
763780
>
@@ -775,5 +792,14 @@ describe("type inference", () => {
775792
void try$.retry(3).timeout(1000).signal(signal).flow
776793
}
777794
})
795+
796+
it("does not expose root type exports from the runtime entrypoint", () => {
797+
if (typecheckOnly()) {
798+
// @ts-expect-error -- settled result types moved to ../types
799+
type _settled = try$.SettledResult<"ok">
800+
// @ts-expect-error -- flow exit types moved to ../types
801+
type _flow = try$.FlowExit<"done">
802+
}
803+
})
778804
})
779805
})

src/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export type {
2+
AllSettledResult,
3+
SettledFulfilled,
4+
SettledRejected,
5+
SettledResult,
6+
} from "./lib/types/all"
7+
export type { FlowExit } from "./lib/types/flow"

0 commit comments

Comments
 (0)