microsoft / microsoft/TypeScript
Empty rest parameter type inferred from candidate function with no rest parameters when "best match" contains a contextually typed argument
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Go
- Star
- 111k
- Fork
- 14.4k
- Merge trung bình
- 1 ngày 19 giờ
- Pull request đã merge (30 ngày)
- 117
Mô tả
Bug Report
🔎 Search Terms
Rest parameter inference contextual
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about type inference
⏯ Playground Link
Playground link with relevant code
💻 Code
const doSomething = <Args extends unknown[]>(
fn1: (aNumber: number, ...rest: Args) => void,
fn2: (aNumber: number, ...rest: Args) => void,
) => {}
// OK, no contextual types
doSomething(
(explicit: number, rest: string) => {}, // Args = [string]
() => {},
)
// OK (both contain contextually typed arg)
doSomething(
(contextual, rest: string) => {}, // Args = [string]
(contextual) => {},
)
// Contextually type only fn1 - Not ok
doSomething(
(contextual, rest: string) => {}, // ERROR
() => {}, // Args = []
)
doSomething(
(contextual, rest: string) => {}, // ERROR
(explicit: number) => {}, // Args = []
)
🙁 Actual behavior
When fn1 (and only fn1) contains a contextually typed argument, it is ignored in favour of fn2
🙂 Expected behavior
In all of the examples, fn2 specifies no rest parameters at all.
I would expect functions that do not specify any rest parameters to always be the least preferable candidate (lowest weight?) for rest parameter inference, since "no rest parameters" can always be assigned to any rest parameter type.
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.
Hướng nghiên cứu
Bắt đầu với bản tái hiện được liên kết trong TypeScript Playground và rút gọn ba lệnh gọi doSomething để cô lập cách contextual typing ảnh hưởng đến việc suy luận tham số rest. Truy vết đường đi kiểm tra kiểu chọn các ứng viên suy luận, sau đó thêm một bài kiểm thử hồi quy cho các trường hợp được nêu; hoàn tất khi kiểu rest [string] của fn1 không bị thay thế bằng [] của fn2.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- typescript
- Lĩnh vực
- compilers
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 35/100