File tree 1 file changed +17
-5
lines changed
1 file changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -83,11 +83,7 @@ class Failure<A> implements ITry<A> {
83
83
export type Try < A > = Success < A > | Failure < A > ;
84
84
export type Unwrapped < A > = A extends Try < infer B > ? Unwrapped < B > : A ;
85
85
86
- export function Try < A > ( value : ( ) => A ) : Try < A > {
87
- return Try . apply ( value ) ;
88
- }
89
-
90
- export namespace Try {
86
+ export namespace TryImplementation {
91
87
export function apply < A > ( value : ( ) => A ) : Try < A > {
92
88
try {
93
89
return new Success < A > ( value ( ) ) ;
@@ -124,6 +120,22 @@ export namespace Try {
124
120
}
125
121
}
126
122
123
+ export interface TryConstructor {
124
+ < A > ( value : ( ) => A ) : Try < A > ;
125
+ new < A > ( value : ( ) => A ) : Try < A > ;
126
+
127
+ apply < A > ( value : ( ) => A ) : Try < A > ;
128
+ success < A > ( value : A | Try < A > ) : Try < Unwrapped < A > > ;
129
+ failure < A = never > ( reason : unknown ) : Try < A > ;
130
+ isOk ( value : unknown ) : value is Success < unknown > ;
131
+ isError ( value : unknown ) : value is Failure < unknown > ;
132
+ isTry ( value : unknown ) : value is Try < unknown > ;
133
+ }
134
+
135
+ export const Try = Object . assign ( function < A > ( value : ( ) => A ) : Try < A > {
136
+ return TryImplementation . apply ( value ) ;
137
+ } , TryImplementation satisfies Omit < TryConstructor , never > ) as TryConstructor ;
138
+
127
139
/* Result Types */
128
140
type ResultOk < T > = {
129
141
ok : true ;
You can’t perform that action at this time.
0 commit comments