Skip to content

@AssertType throws synchronously in async methods #104

Open
@HitoriSensei

Description

@HitoriSensei

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions