Broken typings when upgrading to 21.4.0
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- node.js, typescript
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện ví dụ TypeScript với node.js 22.15.1 và so sánh các định nghĩa kiểu của Request và RouteOptions giữa các phiên bản 21.3.12 và 21.4.0. Truy tìm tính không tương thích liên quan đến route.settings.pre và các kiểu payload generic. Hoàn thành có nghĩa là một someFunction dùng chung có thể chấp nhận requests từ các handlers có payload khác nhau mà không gặp lỗi TS2345 được báo cáo.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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<ResponseObject> => {
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<void> => ({
.....
})
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<ReqRefDefaults>'.
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<ReqRefDefaults> | undefined'.
Type 'RouteOptionsPreArray<{ Payload: { from: string; to: string; }; }>' is not assignable to type 'RouteOptionsPreAllOptions<ReqRefDefaults>[]'.
Type 'RouteOptionsPreAllOptions<{ Payload: { from: string; to: string; }; }>' is not assignable to type 'RouteOptionsPreAllOptions<ReqRefDefaults>'.
Type 'Method<{ Payload: { from: string; to: string; }; }, ReturnValue<{ Payload: { from: string; to: string; }; }>>' is not assignable to type 'RouteOptionsPreAllOptions<ReqRefDefaults>'.
Type 'Method<{ Payload: { from: string; to: string; }; }, ReturnValue<{ Payload: { from: string; to: string; }; }>>' is not assignable to type 'Method<ReqRefDefaults, ReturnValue<ReqRefDefaults>>'.
Types of parameters 'request' and 'request' are incompatible.
Type 'Request<ReqRefDefaults>' is not assignable to type 'Request<{ Payload: { from: string; to: string; }; }>'.
Types of property 'payload' are incompatible.
Type 'string | object | Readable | Buffer<ArrayBufferLike>' 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<void> => ({
.....
})
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.
- Ngôn ngữ chính
- JavaScript
- Star
- 14.8k
- Fork
- 1.4k
- Merge trung bình
- 14 phút
- Pull request đã merge (30 ngày)
- 5
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của hapijs/hapi
-
The data property of a Boom error gets mangled when the error comes from a validatorCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởbug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 70/100
-
The `abort` event on nodejs is deprecatedCó thể làm lại được @akashbirajdar04 đã nhận 187 ngày trước và không có pull request nào đang mở. Đang mởbug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 52/100
-
Error-tracking software doesn't catch hapi application errors if an incoming request gets prematurely closedCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởbug
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
-
Use ECMA Decorators for routingĐang mởfeature
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
Issue tương tự
-
Handle HTTP errors when downloading release binariesCó thể đã có người làm @mugenkyou đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
neutralinojs/neutralinojs-cli#468 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area:ci priority:p0 type:chore
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
lucacasanova/homedeck#2 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
terser/html-minifier-terser#242 ·
-
enhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
MustacheCase/zanadir#516 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
stylelint-scss/stylelint-config-standard-scss#297 · 1 bình luận ·