Domain: JSX/TSXHelp WantedPossible Improvement
描述
🔎 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