-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add shim for ES Promise #33863
Add shim for ES Promise #33863
Conversation
src/shims/promiseShim.ts
Outdated
race<T>(promises: (T | PromiseLike<T>)[]): Promise<T>; | ||
} | ||
|
||
export interface Promise<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I, for one, look forward to Promise is not compatible with ts.Promise
errors. 😄
This feels like a good time to just bump the lib
version to es6
and shim runtime things as needed, rather than adding blocks of stuff onto the es5
lib.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be fine with having ts.Promise
depend on the global native type information for Promise
. What I don't want to do is have our shims insert themselves as the global implementations, as that could cause conflicts with other packages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I definitely just want to use the global Promise
types, though.
Just thought I'll drop an outside opinion: Are all theses inline shims really necessary? Supported Node versions already have Promise/Map/etc implemented. If older web browsers are the concern, wouldn't it be enough to document environment requirements in the Writing this because your time and work are precious to us, the community. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- If Type(value) is not Object, then
- Return FulfillPromise(promise, value).
The current implementation is closer to:
- If Type(value) is not Object or IsCallable(value) is true, then
- Return FulfillPromise(promise, value).
try { | ||
if (promise === value) throw new TypeError(); | ||
// eslint-disable-next-line no-null/no-null | ||
const then = typeof value === "object" && value !== null && (<Promise<unknown>>value).then; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const then = typeof value === "object" && value !== null && (<Promise<unknown>>value).then; | |
const then = ((typeof value === "object" && value !== null) || typeof value === "function") && (<Promise<unknown>>value).then; |
@rbuckton is this still needed? |
@sandersn This was to support async file writing in build mode, which is currently on hold. |
To help with PR housekeeping, I'm going to close this draft PR. It's pretty old. |
This PR adds a shim for the ES Promise, which is needed for some performance-related future work.