polyfill.ts 522 B

123456789101112131415161718192021
  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 };
  10. };
  11. }
  12. if (typeof Array.prototype.at !== 'function') {
  13. Array.prototype.at = function (index: number) {
  14. return index < 0 ? this[this.length + index] : this[index];
  15. };
  16. }
  17. export {};