reactjs / reactjs/react-docgen
Order of intersection types leads to non-deterministic results
Đang mở
Chưa có ai nhận issue này.
question
- Ngôn ngữ chính
- TypeScript
- Star
- 3.8k
- Fork
- 316
- Merge trung bình
- 5 giờ 7 phút
- Pull request đã merge (30 ngày)
- 4
Mô tả
The following:
import React from 'react';
type Props = { children: React.ReactNode; } & { children?: React.ReactNode; }
const Component = ({ children }: Props) => {
return <div>{children}</div>
}
export default Component;
Gives these results:
{
"description": "",
"displayName": "Component",
"methods": [],
"props": {
"children": {
"required": false,
"tsType": {
"name": "ReactReactNode",
"raw": "React.ReactNode"
},
"description": ""
}
}
}
As you can see, children are NOT required, however, if I switch the order of the intersection type:
import React from 'react';
type Props = { children?: React.ReactNode; } & { children: React.ReactNode; }
const Component = ({ children }: Props) => {
return <div>{children}</div>
}
export default Component;
Then the result is different, with children now being required...
{
"description": "",
"displayName": "Component",
"methods": [],
"props": {
"children": {
"required": true,
"tsType": {
"name": "ReactReactNode",
"raw": "React.ReactNode"
},
"description": ""
}
}
}
Is this expected behaviour?
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ái hiện vấn đề với hai ví dụ intersection TypeScript trong báo cáo và so sánh metadata props được tạo ra. Theo dõi cách output của tài liệu xác định liệu children có bắt buộc hay không đối với từng thứ tự intersection. Được xem là hoàn tất khi cả hai thứ tự đều tạo ra cùng một kết quả chính xác về tính bắt buộc.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- react, typescript
- Lĩnh vực
- documentation
- Loại issue
- Lỗi
- Độ 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
- 35/100