Skip to content

Redundant Promise return type on async handlers? #3312

@vjancik

Description

@vjancik

Every async function in JS / TS already returns a Promise. Is this example suggesting every async handler must return a promise that resolves into a promise or is it a wrong return type?

https://docs.nestjs.com/controllers#asynchronicity

#### Asynchronicity
We love modern JavaScript, especially its emphasis on **asynchronous** data handling. That’s why Nest fully supports `async` functions. Every `async` function must return a `Promise`, which allows you to return a deferred value that Nest can resolve automatically. Here's an example:
```typescript
@@filename(cats.controller)
@Get()
async findAll(): Promise<any[]> {
return [];
}
@@switch
@Get()
async findAll() {
return [];
}
```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions