Skip to content
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

Unable to return Promise<void> #51

Closed
RomainMuller opened this issue Jul 3, 2018 · 4 comments · Fixed by #3752
Closed

Unable to return Promise<void> #51

RomainMuller opened this issue Jul 3, 2018 · 4 comments · Fixed by #3752
Labels
bug This issue is a bug. effort/medium Medium work item – a couple days of effort module/compiler Issues affecting the JSII compiler p2

Comments

@RomainMuller
Copy link
Contributor

While methods are fine to return void, they cannot return a Promise<void>, as JSII interprets this as Promise<unknown type>.

Reproduction:

export class PromiseOfVoid {
  async function returnsVoidPromise(): Promise<void> {
    return;
  }
}
@SomayaB SomayaB added the bug This issue is a bug. label Nov 18, 2019
@SomayaB SomayaB added the still-relevant? Checking to see if the issue is still relevant label Dec 19, 2019
@RomainMuller RomainMuller added module/compiler Issues affecting the JSII compiler and removed still-relevant? Checking to see if the issue is still relevant labels Jan 7, 2020
@RomainMuller RomainMuller self-assigned this Jan 7, 2020
@RomainMuller RomainMuller added the p2 label Jan 7, 2020
@RomainMuller RomainMuller added the effort/medium Medium work item – a couple days of effort label Aug 11, 2020
@RomainMuller RomainMuller removed their assignment Jun 24, 2021
@drandell
Copy link

drandell commented Jul 3, 2021

Is there a workaround for this in place?

@Chriscbr
Copy link
Contributor

Chriscbr commented Sep 11, 2022

I also run into this error with Promises that return undefined or null:

export class PromiseOfUndefined {
  async function returnsUndefinedPromise(): Promise<undefined> {
    return;
  }
}
export class PromiseOfNull {
  async function returnsNullPromise(): Promise<null> {
    return;
  }
}

Using jsii 1.67.0.

A possible workaround is to design around the API like so, though it might look unidiomatic for TypeScript/JavaScript users:

export interface Nothing {}

export class PromiseOfNothing {
  async function returnsNothingPromise(): Promise<Nothing> {
    return;
  }
}

@RomainMuller
Copy link
Contributor Author

The undefined and null types are not legal at this stage... which is why these don't work. If they were accepted, they'd likely be treated as synonyms with unknown as these don't otherwise exist in most of our target languages.

Promise<void> should however work, and is currently broken due to a missed edge-case in the compiler I guess. You can use Promise<unknown> in the meantime, as this works.

RomainMuller added a commit that referenced this issue Sep 19, 2022
The void-check only accounted for the literal `void` type, but failed
to account for the `Promise<void>` case. This is now fixed.

Fixes #51
@mergify mergify bot closed this as completed in #3752 Sep 19, 2022
mergify bot pushed a commit that referenced this issue Sep 19, 2022
The void-check only accounted for the literal `void` type, but failed to account for the `Promise<void>` case. This is now fixed.

Fixes #51



---

By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
@github-actions
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. effort/medium Medium work item – a couple days of effort module/compiler Issues affecting the JSII compiler p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants