polyfill.ts 604 B

12345678910111213141516171819202122
  1. if (typeof Promise.withResolvers !== 'function') {
  2. Promise.withResolvers = function <T>() {
  3. let resolve!: (value: T | PromiseLike<T>) => void;
  4. let reject!: (reason?: any) => void;
  5. const promise = new Promise<T>((res, rej) => {
  6. resolve = res;
  7. reject = rej;
  8. });
  9. return { promise, resolve, reject } as PromiseWithResolvers<T>;
  10. };
  11. Object.defineProperty(Promise, 'withResolvers', {});
  12. }
  13. if (typeof Array.prototype.at !== 'function') {
  14. Array.prototype.at = function (index: number) {
  15. return index < 0 ? this[this.length + index] : this[index];
  16. };
  17. }
  18. export {};