@@ -1208,6 +1208,105 @@ interface PromiseLike<T> {
12081208 then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => void): PromiseLike<TResult>;
12091209}
12101210
1211+ /**
1212+ * Represents the completion of an asynchronous operation
1213+ */
1214+ interface Promise<T> {
1215+ /**
1216+ * Attaches callbacks for the resolution and/or rejection of the Promise.
1217+ * @param onfulfilled The callback to execute when the Promise is resolved.
1218+ * @param onrejected The callback to execute when the Promise is rejected.
1219+ * @returns A Promise for the completion of which ever callback is executed.
1220+ */
1221+ then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
1222+
1223+ /**
1224+ * Attaches a callback for only the rejection of the Promise.
1225+ * @param onrejected The callback to execute when the Promise is rejected.
1226+ * @returns A Promise for the completion of the callback.
1227+ */
1228+ catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<T | TResult>;
1229+
1230+ /**
1231+ * Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected).
1232+ * The resolved value cannot be modified from the callback.
1233+ * @param onfinally The callback to execute when the Promise is settled.
1234+ * @returns A Promise for the completion of the callback.
1235+ */
1236+ finally(onfinally?: (() => void) | undefined | null): Promise<T>;
1237+ }
1238+
1239+ interface PromiseConstructor {
1240+ /**
1241+ * A reference to the prototype.
1242+ */
1243+ readonly prototype: Promise<any>;
1244+
1245+ /**
1246+ * Creates a new Promise.
1247+ * @param executor A callback used to initialize the promise. This callback is passed two arguments:
1248+ * a resolve callback used to resolve the promise with a value or the result of another promise,
1249+ * and a reject callback used to reject the promise with a provided reason or error.
1250+ */
1251+ new <T>(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
1252+
1253+ /**
1254+ * Creates a Promise that is resolved with an array of results when all of the provided Promises
1255+ * resolve, or rejected when any Promise is rejected.
1256+ * @param values An array of Promises.
1257+ * @returns A new Promise.
1258+ */
1259+ all<T extends readonly unknown[] | []>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]> }>;
1260+
1261+ /**
1262+ * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
1263+ * or rejected.
1264+ * @param values An array of Promises.
1265+ * @returns A new Promise.
1266+ */
1267+ race<T extends readonly unknown[] | []>(values: T): Promise<Awaited<T[number]>>;
1268+
1269+ /**
1270+ * Creates a new rejected promise for the provided reason.
1271+ * @param reason The reason the promise was rejected.
1272+ * @returns A new rejected Promise.
1273+ */
1274+ reject<T = never>(reason?: any): Promise<T>;
1275+
1276+ /**
1277+ * Creates a new resolved promise.
1278+ * @returns A resolved promise.
1279+ */
1280+ resolve(): Promise<void>;
1281+
1282+ /**
1283+ * Creates a new resolved promise for the provided value.
1284+ * @param value A promise.
1285+ * @returns A promise whose internal state matches the provided promise.
1286+ */
1287+ resolve<T>(value: T): Promise<Awaited<T>>;
1288+
1289+ /**
1290+ * Creates a new resolved promise for the provided value.
1291+ * @param value A promise.
1292+ * @returns A promise whose internal state matches the provided promise.
1293+ */
1294+ resolve<T>(value: T | PromiseLike<T>): Promise<Awaited<T>>;
1295+ }
1296+
1297+ declare var Promise: PromiseConstructor;
1298+
1299+ /**
1300+ * Recursively unwraps the "awaited type" of a type. Non-promise "thenables" should resolve to `never`. This emulates the behavior of `await`.
1301+ */
1302+ type Awaited<T> =
1303+ T extends null | undefined ? T :
1304+ T extends object & { then(onfulfilled: infer F, ...args: infer _): any } ?
1305+ F extends ((value: infer V, ...args: infer _) => any) ?
1306+ Awaited<V> :
1307+ never :
1308+ T;
1309+
12111310interface ArrayLike<T> {
12121311 length: number;
12131312 [n: number]: T;
0 commit comments