Broken typings when upgrading to 21.4.0
- Dominant language
- JavaScript
- Stars
- 14.8k
- Forks
- 1.4k
- Avg merge
- 22d 3h
- Merged PRs (30d)
- 1
Description
### Runtime
node.js
### Runtime version
22.15.1
### Module version
21.4.0
### Last module version without issue
21.3.12
### Used with
_No response_
### Any other relevant information
_No response_
### What are you trying to achieve or the steps to reproduce?
We have handle who look simplified like this:
```
export const create = ():RouteOptions => ({
handler: async (req: Request<{ Payload: { from: string; to: string; } }>, h: ResponseToolkit): Promise => {
const from = req.payload.from
const to = req.payload.to
.....
await someFunction(req);
return h.response().code(201);
},
});
export const someFunction = async (request: Request): Promise => ({
.....
})
```
### What was the result you got?
I get a typescript error:
```
error TS2345: Argument of type 'Request<{ Payload: { from: string; to: string; }; }>' is not assignable to parameter of type 'Request'.
The types of 'route.settings.pre' are incompatible between these types.
Type 'RouteOptionsPreArray<{ Payload: { from: string; to: string; }; }> | undefined' is not assignable to type 'RouteOptionsPreArray | undefined'.
Type 'RouteOptionsPreArray<{ Payload: { from: string; to: string; }; }>' is not assignable to type 'RouteOptionsPreAllOptions[]'.
Type 'RouteOptionsPreAllOptions<{ Payload: { from: string; to: string; }; }>' is not assignable to type 'RouteOptionsPreAllOptions'.
Type 'Method<{ Payload: { from: string; to: string; }; }, ReturnValue<{ Payload: { from: string; to: string; }; }>>' is not assignable to type 'RouteOptionsPreAllOptions'.
Type 'Method<{ Payload: { from: string; to: string; }; }, ReturnValue<{ Payload: { from: string; to: string; }; }>>' is not assignable to type 'Method>'.
Types of parameters 'request' and 'request' are incompatible.
Type 'Request' is not assignable to type 'Request<{ Payload: { from: string; to: string; }; }>'.
Types of property 'payload' are incompatible.
Type 'string | object | Readable | Buffer' is not assignable to type '{ from: string; to: string; }'.
Type 'string' is not assignable to type '{ from: string; to: string; }'.
```
To fix this problem I need to change:
```
export const someFunction = async (request: Request<{ Payload: { from: string; to: string; } }>): Promise => ({
.....
})
```
but this does not work out if `someFunction` is used by different handler with different payloads.
### What result did you expect?
keep it the way as in 21.3.12 an not have an error here.
Contributor guide
Assessment
This issue has not been assessed yet.