-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
fix(core/types): Promise.withResolvers
: Unmark callback param as optional
#21085
Conversation
See 1d19b10#r131604700 Signed-off-by: Jesse Jackson <jsejcksn@users.noreply.github.com>
Updated to deno_core 0.224.0 and V8 12.0. --------- Co-authored-by: Aapo Alasuutari <aapo.alasuutari@gmail.com>
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.
Thanks!
@jsejcksn I think this is not not quite right, with this change it's not possible to resolve without a value:
While the JS API accepts it without a problem:
|
@bartlomieju That's the correct, expected behavior. In TypeScript
new Promise((resolve) => {
//^? (parameter) resolve: (value: unknown) => void
resolve(); /* Error:
~~~~~~~~~
Expected 1 arguments, but got 0. Did you forget to include 'void' in your type argument to 'Promise'? (2794) */
});
new Promise<void>((resolve) => {
//^? (parameter) resolve: (value: void | PromiseLike<void>) => void
resolve(); // Ok
});
declare global {
interface PromiseConstructor {
withResolvers<T>(): {
promise: Promise<T>;
resolve: (value: T | PromiseLike<T>) => void;
reject: (reason?: any) => void;
};
}
}
{
const { promise, resolve } = Promise.withResolvers();
//^? const resolve: (value: unknown) => void
resolve(); /* Error:
~~~~~~~~~
Expected 1 arguments, but got 0. (2554) */
await promise;
}
{
const { promise, resolve } = Promise.withResolvers<void>();
//^? const resolve: (value: void | PromiseLike<void>) => void
resolve(); // Ok
await promise;
} Terminal: % deno --version
deno 1.38.0 (release, aarch64-apple-darwin)
v8 12.0.267.1
typescript 5.2.2
% deno check example.ts
Check file:///Users/deno/example.ts
error: TS2794 [ERROR]: Expected 1 arguments, but got 0. Did you forget to include 'void' in your type argument to 'Promise'?
resolve(); /* Error:
~~~~~~~~~
at file:///Users/deno/example.ts:3:3
An argument for 'value' was not provided.
new <T>(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
~~~~~~~~~~~~~~~~~~~~~~~~~
at asset:///lib.es2015.promise.d.ts:31:34
TS2554 [ERROR]: Expected 1 arguments, but got 0.
resolve(); /* Error:
~~~~~~~~~
at file:///Users/deno/example.ts:26:3
An argument for 'value' was not provided.
resolve: (value: T | PromiseLike<T>) => void;
~~~~~~~~~~~~~~~~~~~~~~~~~
at file:///Users/deno/example.ts:17:17
Found 2 errors.
|
@bartlomieju Re: the partial error message you included:
All the checks passed for this PR before it was merged, so I'm not sure how that was run. It looks like that came from here: deno/cli/tests/unit/cron_test.ts Lines 200 to 221 in fdb4953
And it looks like the values I'm guessing that the changes which need to be made are to annotate the - const promise0 = deferred();
- const promise1 = deferred();
+ const promise0 = deferred<void>();
+ const promise1 = deferred<void>(); |
@jsejcksn The change I applied was changing I guess it's okay to change all call sites in |
See discussion on merged commit: 1d19b10#r131604700