microsoft / microsoft/TypeScript
Template Literal Type JSX children prop issue
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the crash in the linked TypeScript Playground using the JSX example and template literal children type. Start by tracing JSX children-prop checking for values between opening and closing tags, then verify that the expected behavior works without breaking named-prop passing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100