microsoft / microsoft/TypeScript
Allow inferring return type within a type guard in conditional types
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
typeguard conditional infer
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about (bug reporting)
⏯ Playground Link
Playground link with relevant code
💻 Code
This is simplified pretty heavily:
type InferredTypeGuard<TypeGuard> =
TypeGuard extends ((node: infer Input) => node is infer Output)
? (node: Input) => node is Output
: never;
🙁 Actual behavior
Error on infer Output:
A type predicate's type must be assignable to its parameter's type.
Type 'Output' is not assignable to type 'Input'.
'Input' could be instantiated with an arbitrary type which could be unrelated to 'Output'.(2677)
🙂 Expected behavior
TypeScript should allow a conditional type to infer the Output type within the type guard function's return type.
There's no other syntax I can find to do so, and I would have thought this would be the cleanest syntax. Not sure if bug report or feature request...
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 ví dụ TypeScript Playground được liên kết và kiểu có điều kiện được đơn giản hóa sử dụng infer Input và infer Output. Theo dõi quá trình kiểm tra tính có thể gán của vị từ kiểu, quá trình báo lỗi 2677, và xác định suy luận kiểu có điều kiện nên tương tác với nó như thế nào. Hoàn thành khi ví dụ kiểm tra kiểu thành công với các kiểu đầu vào và đầu ra được suy luận như mong đợi, đồng thời có phạm vi kiểm thử hồi quy cho hành vi này.
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
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 25/100