microsoft / microsoft/TypeScript
FormData methods should take a Generic
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Go
- Star
- 111k
- Fork
- 14.3k
- Merge trung bình
- 2 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 132
Mô tả
Suggestion
🔍 Search Terms
Form Data, .entries()
✅ Viability Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
⭐ Suggestion
FormData entries() method, and perhaps .keys() and .values() should take a generic.
Right now it returns FormDataEntry value and is difficult type type the returned value of that Iterable.
📃 Motivating Example
Example of the problem here:
Feeding the .entries() Iterable into Object.fromEntries(), gives us a type of { [k: string]: FormDataEntryValue; }, and has no overlap between the acutal data (Person in my case) that is supposed to come back.
So perhaps something like formData.entries<Person>() or formData.entries<IterableIterator<Person>>()?
I just know it's really hard to convert the result into a type. And the solutions are either as unknown as Person or a Type Guard, which makes me manually type each property.
💻 Use Cases
See above link example
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 TypeScript playground được liên kết và kiểm tra các kiểu của FormData.entries(), keys() và values() khi được truyền vào Object.fromEntries(). So sánh hành vi generic được yêu cầu với kết quả FormDataEntryValue hiện tại và xác định liệu có thể tạo một định nghĩa vững chắc, không gây breaking change hay không; hoàn thành có nghĩa là ví dụ thúc đẩy yêu cầu nhận được một kiểu hữu ích mà không cần các unsafe assertions.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, typescript
- Lĩnh vực
- devtools
- 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
- 30/100