Skip to content

Promise<unknown> is not assignable to Promise<void> #44201

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

Closed
kkirby opened this issue May 21, 2021 · 2 comments
Closed

Promise<unknown> is not assignable to Promise<void> #44201

kkirby opened this issue May 21, 2021 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@kkirby
Copy link

kkirby commented May 21, 2021

Bug Report

Currently unknown is assignable to void. However, Promise<unknown> is NOT assignable to Promise<void>.

🔎 Search Terms

promise, type compatibility, assignment

🕗 Version & Regression Information

This is the behavior in every version I tried, and I reviewed the FAQ

⏯ Playground Link

Playground link with relevant code

💻 Code

const voidPromiseFn = async () => {}
const voidFn = () => {};

const unknownPromiseFn = async (): Promise<unknown> => void 0;
const unknownFn = (): unknown => void 0;

const takesVoidPromiseFn = (fn: typeof voidPromiseFn) => {};
const takesVoidFn = (fn: typeof voidFn) => {};

// This works
takesVoidFn(voidFn);
// This works
takesVoidFn(unknownFn);

// This works
takesVoidPromiseFn(voidPromiseFn);
// This does NOT work
takesVoidPromiseFn(unknownPromiseFn);

const takesVoidPromise = (fn: Promise<void>) => {};

// This works
takesVoidPromise(new Promise<void>(() => {}));
// This does NOT work
takesVoidPromise(new Promise<unknown>(() => {}));

🙁 Actual behavior

A function that returns Promise<unknown> (() => Promise<unknown>) could not be passed as a function argument with the type () => Promise<void>. Contradictory, a function that returns unknown (() => unknown) can be passed to a function argument with the type () => void.

🙂 Expected behavior

I would expect that passing a () => Promise<unknown> to a function argument that accepts () => Promise<void> to be allowed.

@MartinJohns
Copy link
Contributor

Duplicate of #12871.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label May 27, 2021
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants