Microsoft/TypeScript
GitHub ã§èŠãTemplate Literal Type JSX children prop issue
Open
#58,799 opened on 2024幎6æ7æ¥
Domain: JSX/TSXHelp WantedPossible Improvement
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
ð 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