Skip to content

Commit ca6a25b

Browse files
committed
feat: add ErrFactory type to err.ts.
Using Err in some other libraries has led to a proliferation of slow-type errors related to exported const error factories. This should help resolve that issue.
1 parent 3ac36d0 commit ca6a25b

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@baetheus/fun",
3-
"version": "3.0.0-rc.5",
3+
"version": "3.0.0-rc.6",
44
"exports": {
55
"./applicable": "./applicable.ts",
66
"./array": "./array.ts",

err.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ export type Err<T extends string, A> = {
4848
// deno-lint-ignore no-explicit-any
4949
export type AnyErr = Err<string, any>;
5050

51+
/**
52+
* A type alias for an Err factory returned by the err function. This is useful
53+
* to combat deno slow-types errors on publish.
54+
*
55+
* @since 3.0.0-rc.6
56+
*/
57+
export type ErrFactory<T extends string> = <A>(
58+
message: string,
59+
context?: A,
60+
) => Err<T, A>;
61+
5162
/**
5263
* Create a constructor function for a specific error type.
5364
*
@@ -67,7 +78,7 @@ export type AnyErr = Err<string, any>;
6778
*/
6879
export function err<T extends string>(
6980
name: T,
70-
): <A>(message: string, context?: A) => Err<T, A> {
81+
): ErrFactory<T> {
7182
return (message, context) => ({
7283
tag: "Error",
7384
name,

0 commit comments

Comments
 (0)