microsoft / microsoft/TypeScript
Template Literal Type JSX children prop issue
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ả
🔎 Search Terms
"2745", "template literal type", "multiple children", "single child"
🕗 Version & Regression Information
- This is a crash
⏯ Playground Link
💻 Code
function App() {
return (
<>
{/* This works as expected */}
<ComponentWithTemplateLiteralTypeChildrenProp children="a_hello"></ComponentWithTemplateLiteralTypeChildrenProp>
{/* This JSX tag's 'children' prop expects type '`a_${string}` | `b_${string}`' which requires multiple children, but only a single child was provided. (2745) */}
<ComponentWithTemplateLiteralTypeChildrenProp>a_hello</ComponentWithTemplateLiteralTypeChildrenProp>
</>
);
}
type Prefix = 'a_' | 'b_';
type Prop = `${Prefix}${string}`;
function ComponentWithTemplateLiteralTypeChildrenProp({ children }: { children: Prop }) {
return <span>{children}</span>;
}
🙁 Actual behavior
A Template Literal Type "children" prop does not allow the prop to be passed between the open/close tags. Passing the value via a prop works.
🙂 Expected behavior
It should be possible to pass a Template Literal Type "children" prop in between the open/close tags. Not only via a named prop.
Additional information about the issue
No response
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
Tái hiện crash trong TypeScript Playground được liên kết bằng ví dụ JSX và kiểu children của template literal. Bắt đầu bằng cách lần theo việc kiểm tra prop children của JSX đối với các giá trị nằm giữa thẻ mở và thẻ đóng, sau đó xác minh rằng hành vi mong đợi hoạt động mà không làm hỏng việc truyền các prop có tên.
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
- Khá rõ ràng
- Mức phù hợp với người mới
- 45/100