Skip to content

Commit 9ed0ab0

Browse files
committed
chore: make fn parameter required
1 parent e26c833 commit 9ed0ab0

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ type Result<T, E = Error> = ([data: T, error: null] | [data: null, error: E]) &
483483
### Edge Cases
484484
485485
```ts
486-
tryCatch(); // Returns [undefined, null]
486+
tryCatch(undefined); // Returns [undefined, null]
487487
tryCatch(null); // Returns [null, null]
488488
tryCatch(() => {
489489
throw new Error("Unexpected Error");

packages/try-catch-tuple/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ type Result<T, E = Error> = [data: T, error: null] | [data: null, error: E];
266266
## Edge Cases
267267
268268
```ts
269-
tryCatch(); // Returns [undefined, null]
269+
tryCatch(undefined); // Returns [undefined, null]
270270
tryCatch(null); // Returns [null, null]
271271
tryCatch(() => {
272272
throw new Error("Unexpected Error");

packages/try-catch-tuple/src/tryCatch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type TryCatchResult<T, E extends Error> = T extends Promise<infer U>
88
: Result<T, E>;
99

1010
type TryCatchFunc<E_ extends Error = Error> = <T, E extends Error = E_>(
11-
fn?: T | (() => T),
11+
fn: T | (() => T),
1212
operationName?: string,
1313
) => TryCatchResult<T, E>;
1414

@@ -36,7 +36,7 @@ type TryCatch<
3636
* @returns A Result, or a Promise resolving to a Result, depending on fn.
3737
*/
3838
export const tryCatch: TryCatch = <T, E extends Error = Error>(
39-
fn?: T | (() => T),
39+
fn: T | (() => T),
4040
operationName?: string,
4141
) => {
4242
try {

packages/try-catch-tuple/tests/tryCatch.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ describe("tryCatch", () => {
344344

345345
describe("edge cases", () => {
346346
test("should handle undefined fn", () => {
347-
const [result, error] = tryCatch();
347+
const [result, error] = tryCatch(undefined);
348+
if (error) expect.unreachable();
348349
expect(result).toBe(undefined);
349350
expect(error).toBeNil();
350351
});

0 commit comments

Comments
 (0)