microsoft / microsoft/TypeScript
TypedPropertyDescriptorMap<T>
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ả
Search Terms
TypedPropertyDescriptor
TypedPropertyDescriptorMap
Typed Property Descriptor Map
Suggestion
Include TypedPropertyDescriptorMap<T>, the typed version of PropertyDescriptorMap. The following type should do the trick:
type TypedPropertyDescriptorMap<T> = {
[P in keyof T]: TypedPropertyDescriptor<T[P]>
}
This would require a change to the Object.defineProperties type definition since it only accepts a PropertyDescriptorMap type, an indexed type. Passing in an object with a type of TypedPropertyDescriptorMap<T> results in the error: Index signature is missing in type 'TypedPropertyDescriptorMap<T>'. There's a related issue on this topic (https://github.com/Microsoft/TypeScript/issues/15300).
Use Cases
It's a headache to have to define a type like the following when I already have defined the final object type:
// Final object looks like
interface MyProps {
prop1: string
prop2: (params: Record<string, string>) => Promise<void>
}
// My custom TypedPropertyDescriptor map
interface MyPropDescriptors {
prop1: TypedPropertyDescriptor<MyProps['prop1']>
prop2: TypedPropertyDescriptor<MyProps['prop2']>
...
}
Examples
// Final object looks like
interface MyProps {
prop1: string
prop2: (params: Record<string, string>) => Promise<void>
}
// My custom TypedPropertyDescriptor map
type MyPropDescriptors = TypedPropertyDescriptorMap<MyProps>
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, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
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 bằng cách tìm khai báo của Object.defineProperties và các kiểu TypedPropertyDescriptor và PropertyDescriptorMap hiện có. Xem xét issue liên quan #15300, sau đó xác minh mapped type được đề xuất và việc Object.defineProperties chấp nhận nó bằng một type-checking test tập trung; hoàn tất khi các descriptor maps được định kiểu hoạt động mà không có index-signature error.
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ó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- 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
- 43/100