-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.d.ts
38 lines (35 loc) · 979 Bytes
/
main.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import type { ErrorName } from 'error-class-utils'
export type { ErrorName }
/**
* Custom error class
*/
// eslint-disable-next-line fp/no-class
export declare class CustomError<
ErrorNameArg extends ErrorName = ErrorName,
Options extends object = object,
> extends Error {
constructor(message: string, params?: Options & { cause?: unknown })
name: ErrorNameArg
}
/**
* Creates a custom error class.
*
* @example
* ```js
* import errorCustomClass from 'error-custom-class'
*
* const UserError = errorCustomClass('UserError')
* const DatabaseError = errorCustomClass('DatabaseError')
*
* try {
* throw new UserError('message')
* } catch (error) {
* console.log(error.name) // 'UserError'
* console.log(error instanceof UserError) // true
* }
* ```
*/
export default function errorCustomClass<
ErrorNameArg extends ErrorName = ErrorName,
Options extends object = object,
>(errorName: ErrorNameArg): typeof CustomError<ErrorNameArg, Options>