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

@AssertType throws synchronously in async methods #104

Open
HitoriSensei opened this issue Jun 30, 2021 · 1 comment
Open

@AssertType throws synchronously in async methods #104

HitoriSensei opened this issue Jun 30, 2021 · 1 comment

Comments

@HitoriSensei
Copy link
Contributor

HitoriSensei commented Jun 30, 2021

When using @AssertType decoator on async methods, calling the method throws synchronously instead of returning rejected promise.

example:

@ValidateClass()
export class MessageHandler {
  async handleMessage(@AssertType() body: { feedId: string }): Promise<void> {
    console.log(body);
  }
}

new MessageHandler()
  .handleMessage({ invalidMessage: 123 }) // error: throws synchronously here!
  .catch(e => {
    // …should be able to handle TypeGuardError here
  })

It would be perfect to make @AssertType aware of async keyword or Promise return type, but is it even possible?

@HitoriSensei
Copy link
Contributor Author

I've done my research on decorators and metadata and prepared a PR addressing the issue:
https://github.com/woutervh-/typescript-is/pull/105

woutervh- added a commit that referenced this issue Nov 1, 2021
#104 @AssertType rejects a promise when used in async methods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant