-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.d.ts
87 lines (83 loc) · 1.83 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* Undo `polyfill()`
*
* @example
* ```js
* import { polyfill } from 'error-cause-polyfill'
*
* const undoPolyfill = polyfill()
* undoPolyfill()
* ```
*/
export type UndoPolyfill = () => void
/**
* Modifies the global error classes (`Error`, `TypeError`, etc.) so they
* support `error.cause`. If `error.cause` is already supported, this is a noop.
*
* This returns a function to undo everything.
*
* @example
* ```js
* import { polyfill } from 'error-cause-polyfill'
*
* polyfill()
*
* try {
* doSomething()
* } catch (cause) {
* throw new Error('message', { cause })
* }
* ```
*/
export function polyfill(): UndoPolyfill
/**
* Object with each error class (`Error`, `TypeError`, etc.) but with
* `error.cause` support.
*/
export interface Errors {
Error: Error
ReferenceError: Error
TypeError: Error
SyntaxError: Error
RangeError: Error
URIError: Error
EvalError: Error
/**
* `undefined` if the system does not support `AggregateError`
*/
AggregateError?: Error
}
/**
* Returns an object with each error class (`Error`, `TypeError`, etc.) but with
* `error.cause` support. If `error.cause` is already supported, this returns
* the global error classes as is.
*
* Unlike `polyfill()`, this does not modify the global error classes.
*
* @example
* ```js
* import { getErrors } from 'error-cause-polyfill'
*
* const Errors = getErrors()
*
* try {
* doSomething()
* } catch (cause) {
* throw new Errors.Error('message', { cause })
* }
* ```
*/
export function getErrors(): Errors
/**
* Returns whether the global error classes currently support `error.cause`.
*
* @example
* ```js
* import { hasSupport, polyfill } from 'error-cause-polyfill'
*
* console.log(hasSupport()) // false
* polyfill()
* console.log(hasSupport()) // true
* ```
*/
export function hasSupport(): boolean