fastify / fastify/help

onSendHookHandler: no option for payload type

Open
#612 2 comments 0 reactions 0 assignees View on GitHub
help wanted
Dominant language
No language data
Stars
68
Forks
8
Avg merge
11h 2m
Merged PRs (30d)
2

Description

When implementing a function for onSend hook - there is no option to pass a type for onSendHookHandler and it's assuming that the payload is of `unknown` type

```js
// this code is not working:
export const myHook = (): onSendHookHandler => {
return async (req: FastifyRequest, rep: FastifyReply, payload: string) => {
....
}
}

// this code is working:
export const myHook = (): onSendHookHandler => {
return async (req: FastifyRequest, rep: FastifyReply, payload: unknown) => {
....
}
}
````

If onSendHookHandler supports generics - why we can't use it when declaring onSend:
```
onSend?: onSendHookHandler | onSendHookHandler[];
```

## Your Environment

- *node version*: 14
- *fastify version*: >=3.22.0
- *os*: Macx

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.