TS error cloneElement children
See original GitHub issueReproduction
https://codesandbox.io/s/strange-wilson-w6k4p
Steps to reproduce
- Use
preact@10.3.4
- Pass
props.children
tocloneElement
.
Expected Behavior
As per the documentation example, this should be valid. Thus, no TS errors should occur.
Actual Behavior
TS reports the following error:
No overload matches this call.
Overload 1 of 2, '(vnode: VNode<any>, props?: any, ...children: ComponentChildren[]): VNode<any>', gave the following error.
Argument of type 'ComponentChildren' is not assignable to parameter of type 'VNode<any>'.
Type 'undefined' is not assignable to type 'VNode<any>'.
Overload 2 of 2, '(vnode: VNode<any>, props?: any, ...children: ComponentChildren[]): VNode<any>', gave the following error.
Argument of type 'ComponentChildren' is not assignable to parameter of type 'VNode<any>'.
Type 'undefined' is not assignable to type 'VNode<any>'.ts(2769)
Update 2020-03-26 15:33:17Z
Possibly related to issue #650, though the TS error existed before in a different format.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Typescript(ing) React.cloneElement or how to type a child ...
cloneElement to create a new component which is received as a child (using props.chidren) and to ... which works, does the job, but...
Read more >How to assign the correct typing to React.cloneElement when ...
cloneElement I get the following error from Typescript: Argument of type 'ReactChild' is not assignable to parameter of type 'ReactElement<any>' ...
Read more >React Children Map and cloneElement using TypeScript
This article shows how you can use the React Children map function together with React cloneElement function to add additional props to ...
Read more >react cloneElement TypeScript Examples - ProgramCreek.com
1) { throw new Error('<DOMView /> must have a single child.') } return <> {cloneElement(this.props.children, { ref: this.ref, })} </> }. Example #10 ......
Read more >How to define props in TypeScript where a parent component ...
When a component clones its children to inject props into them, how to ... /Parent> Error in Child: injectedProp is missing. ... index.d.ts...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I could give it a shot.
Took at stab at resolving this. In fact, I believe my changes caused this type error. Hope you don’t mind!