-
-
Notifications
You must be signed in to change notification settings - Fork 679
Expand file tree
/
Copy pathstructured-cloneable.d.ts
More file actions
89 lines (76 loc) · 1.9 KB
/
structured-cloneable.d.ts
File metadata and controls
89 lines (76 loc) · 1.9 KB
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
88
89
import type {TypedArray} from './typed-array.d.ts';
import type {FindGlobalInstanceType} from './find-global-type.d.ts';
type StructuredCloneablePrimitive =
| string
| number
| bigint
| boolean
| null
| undefined
| Boolean
| Number
| String;
type StructuredCloneableData =
| ArrayBuffer
| DataView
| Date
| Error
| RegExp
| TypedArray
| FindGlobalInstanceType<
// DOM or Node types
| 'Blob'
| 'File'
// DOM exclusive types
| 'AudioData'
| 'CropTarget'
| 'CryptoKey'
| 'DOMException'
| 'DOMMatrix'
| 'DOMMatrixReadOnly'
| 'DOMPoint'
| 'DOMPointReadOnly'
| 'DOMQuad'
| 'DOMRect'
| 'DOMRectReadOnly'
| 'FileList'
| 'FileSystemDirectoryHandle'
| 'FileSystemFileHandle'
| 'FileSystemHandle'
| 'GPUCompilationInfo'
| 'GPUCompilationMessage'
| 'ImageBitmap'
| 'ImageData'
| 'RTCCertificate'
| 'VideoFrame'
>;
type StructuredCloneableCollection =
| readonly StructuredCloneable[]
| {readonly [key: string]: StructuredCloneable; readonly [key: number]: StructuredCloneable}
| ReadonlyMap<StructuredCloneable, StructuredCloneable>
| ReadonlySet<StructuredCloneable>;
/**
Matches a value that can be losslessly cloned using `structuredClone`.
Note:
- Custom error types will be cloned as the base `Error` type
@see https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm
@example
```
import type {StructuredCloneable} from 'type-fest';
class CustomClass {}
const error = {
custom: new CustomClass(),
// @ts-expect-error
} satisfies StructuredCloneable;
const good = {
number: 3,
date: new Date(),
map: new Map<string, number>(),
} satisfies StructuredCloneable;
const clonedGood = structuredClone(good);
//=> {number: number; date: Date; map: Map<string, number>}
```
@category Structured clone
*/
export type StructuredCloneable = StructuredCloneablePrimitive | StructuredCloneableData | StructuredCloneableCollection;
export {};