typescript 5.2.0-dev.20230622 → 5.2.0-dev.20230623

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,3 +18,4 @@ and limitations under the License.
18
18
 
19
19
  /// <reference lib="es2023" />
20
20
  /// <reference lib="esnext.intl" />
21
+ /// <reference lib="esnext.disposable" />
@@ -0,0 +1,185 @@
1
+ /*! *****************************************************************************
2
+ Copyright (c) Microsoft Corporation. All rights reserved.
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4
+ this file except in compliance with the License. You may obtain a copy of the
5
+ License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8
+ KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9
+ WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10
+ MERCHANTABLITY OR NON-INFRINGEMENT.
11
+
12
+ See the Apache Version 2.0 License for specific language governing permissions
13
+ and limitations under the License.
14
+ ***************************************************************************** */
15
+
16
+
17
+ /// <reference no-default-lib="true"/>
18
+
19
+ /// <reference lib="es2015.symbol" />
20
+
21
+ interface SymbolConstructor {
22
+ /**
23
+ * A method that is used to release resources held by an object. Called by the semantics of the `using` statement.
24
+ */
25
+ readonly dispose: unique symbol;
26
+
27
+ /**
28
+ * A method that is used to asynchronously release resources held by an object. Called by the semantics of the `await using` statement.
29
+ */
30
+ readonly asyncDispose: unique symbol;
31
+ }
32
+
33
+ interface Disposable {
34
+ [Symbol.dispose](): void;
35
+ }
36
+
37
+ interface AsyncDisposable {
38
+ [Symbol.asyncDispose](): PromiseLike<void>;
39
+ }
40
+
41
+ interface SuppressedError extends Error {
42
+ error: any;
43
+ suppressed: any;
44
+ }
45
+
46
+ interface SuppressedErrorConstructor extends ErrorConstructor {
47
+ new (error: any, suppressed: any, message?: string): SuppressedError;
48
+ (error: any, suppressed: any, message?: string): SuppressedError;
49
+ readonly prototype: SuppressedError;
50
+ }
51
+ declare var SuppressedError: SuppressedErrorConstructor;
52
+
53
+ interface DisposableStack {
54
+ /**
55
+ * Returns a value indicating whether this stack has been disposed.
56
+ */
57
+ readonly disposed: boolean;
58
+ /**
59
+ * Disposes each resource in the stack in the reverse order that they were added.
60
+ */
61
+ dispose(): void;
62
+ /**
63
+ * Adds a disposable resource to the stack, returning the resource.
64
+ * @param value The resource to add. `null` and `undefined` will not be added, but will be returned.
65
+ * @returns The provided {@link value}.
66
+ */
67
+ use<T extends Disposable | null | undefined>(value: T): T;
68
+ /**
69
+ * Adds a value and associated disposal callback as a resource to the stack.
70
+ * @param value The value to add.
71
+ * @param onDispose The callback to use in place of a `[Symbol.dispose]()` method. Will be invoked with `value`
72
+ * as the first parameter.
73
+ * @returns The provided {@link value}.
74
+ */
75
+ adopt<T>(value: T, onDispose: (value: T) => void): T;
76
+ /**
77
+ * Adds a callback to be invoked when the stack is disposed.
78
+ */
79
+ defer(onDispose: () => void): void;
80
+ /**
81
+ * Move all resources out of this stack and into a new `DisposableStack`, and marks this stack as disposed.
82
+ * @example
83
+ * ```ts
84
+ * class C {
85
+ * #res1: Disposable;
86
+ * #res2: Disposable;
87
+ * #disposables: DisposableStack;
88
+ * constructor() {
89
+ * // stack will be disposed when exiting constructor for any reason
90
+ * using stack = new DisposableStack();
91
+ *
92
+ * // get first resource
93
+ * this.#res1 = stack.use(getResource1());
94
+ *
95
+ * // get second resource. If this fails, both `stack` and `#res1` will be disposed.
96
+ * this.#res2 = stack.use(getResource2());
97
+ *
98
+ * // all operations succeeded, move resources out of `stack` so that they aren't disposed
99
+ * // when constructor exits
100
+ * this.#disposables = stack.move();
101
+ * }
102
+ *
103
+ * [Symbol.dispose]() {
104
+ * this.#disposables.dispose();
105
+ * }
106
+ * }
107
+ * ```
108
+ */
109
+ move(): DisposableStack;
110
+ [Symbol.dispose](): void;
111
+ readonly [Symbol.toStringTag]: string;
112
+ }
113
+
114
+ interface DisposableStackConstructor {
115
+ new(): DisposableStack;
116
+ readonly prototype: DisposableStack;
117
+ }
118
+ declare var DisposableStack: DisposableStackConstructor;
119
+
120
+ interface AsyncDisposableStack {
121
+ /**
122
+ * Returns a value indicating whether this stack has been disposed.
123
+ */
124
+ readonly disposed: boolean;
125
+ /**
126
+ * Disposes each resource in the stack in the reverse order that they were added.
127
+ */
128
+ disposeAsync(): Promise<void>;
129
+ /**
130
+ * Adds a disposable resource to the stack, returning the resource.
131
+ * @param value The resource to add. `null` and `undefined` will not be added, but will be returned.
132
+ * @returns The provided {@link value}.
133
+ */
134
+ use<T extends AsyncDisposable | Disposable | null | undefined>(value: T): T;
135
+ /**
136
+ * Adds a value and associated disposal callback as a resource to the stack.
137
+ * @param value The value to add.
138
+ * @param onDisposeAsync The callback to use in place of a `[Symbol.asyncDispose]()` method. Will be invoked with `value`
139
+ * as the first parameter.
140
+ * @returns The provided {@link value}.
141
+ */
142
+ adopt<T>(value: T, onDisposeAsync: (value: T) => PromiseLike<void> | void): T;
143
+ /**
144
+ * Adds a callback to be invoked when the stack is disposed.
145
+ */
146
+ defer(onDisposeAsync: () => PromiseLike<void> | void): void;
147
+ /**
148
+ * Move all resources out of this stack and into a new `DisposableStack`, and marks this stack as disposed.
149
+ * @example
150
+ * ```ts
151
+ * class C {
152
+ * #res1: Disposable;
153
+ * #res2: Disposable;
154
+ * #disposables: DisposableStack;
155
+ * constructor() {
156
+ * // stack will be disposed when exiting constructor for any reason
157
+ * using stack = new DisposableStack();
158
+ *
159
+ * // get first resource
160
+ * this.#res1 = stack.use(getResource1());
161
+ *
162
+ * // get second resource. If this fails, both `stack` and `#res1` will be disposed.
163
+ * this.#res2 = stack.use(getResource2());
164
+ *
165
+ * // all operations succeeded, move resources out of `stack` so that they aren't disposed
166
+ * // when constructor exits
167
+ * this.#disposables = stack.move();
168
+ * }
169
+ *
170
+ * [Symbol.dispose]() {
171
+ * this.#disposables.dispose();
172
+ * }
173
+ * }
174
+ * ```
175
+ */
176
+ move(): AsyncDisposableStack;
177
+ [Symbol.asyncDispose](): Promise<void>;
178
+ readonly [Symbol.toStringTag]: string;
179
+ }
180
+
181
+ interface AsyncDisposableStackConstructor {
182
+ new(): AsyncDisposableStack;
183
+ readonly prototype: AsyncDisposableStack;
184
+ }
185
+ declare var AsyncDisposableStack: AsyncDisposableStackConstructor;