-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
CommittedThe team has roadmapped this issueThe team has roadmapped this issueSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
Description
Imagine a component which requires some exact number of children passed.
Can it be currently expressed in TypeScript? Tuple doesn't work here.
Code
import React from 'react'
interface ResizablePanelProps {
children: [React.ReactNode, React.ReactNode]
}
class ResizablePanel extends React.Component<
ResizablePanelProps, any> {}
const test = <ResizablePanel>
<div />
<div />
</ResizablePanel>
Expected behavior:
Pass.
Actual behavior:
Type '{ children: Element[]; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<ResizablePanel> & Readonly<{ children?: ReactNode;...'.
Type '{ children: Element[]; }' is not assignable to type 'Readonly<ResizablePanelProps>'.
Types of property 'children' are incompatible.
Type 'Element[]' is not assignable to type '[ReactNode, ReactNode]'.
Property '0' is missing in type 'Element[]'.
Code
import React from 'react'
interface ResizablePanelProps {
children: [React.ReactNode, React.ReactNode]
}
class ResizablePanel extends React.Component<
ResizablePanelProps, any> {}
const test = <ResizablePanel>
<div />
<div />
<div />
</ResizablePanel>
Expected behavior:
Fail, provided 3 nodes instead of 2.
Playground Link:
https://stackblitz.com/edit/react-ts-8tttua
cshaa, Cryrivers, shimil, Igorbek, dylanede and 2 more
Metadata
Metadata
Assignees
Labels
CommittedThe team has roadmapped this issueThe team has roadmapped this issueSuggestionAn idea for TypeScriptAn idea for TypeScript