Microsoft/TypeScript
Auf GitHub ansehenTemplate Literal Type JSX children prop issue
Open
#58.799 geöffnet am 7. Juni 2024
Domain: JSX/TSXHelp WantedPossible Improvement
Repository-Metriken
- Stars
- (48.455 Stars)
- PR-Merge-Metriken
- (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)
Beschreibung
🔎 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