question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TS error cloneElement children

See original GitHub issue

Reproduction

https://codesandbox.io/s/strange-wilson-w6k4p

Steps to reproduce

  • Use preact@10.3.4
  • Pass props.children to cloneElement.

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:open
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Frikkicommented, Apr 6, 2020

Would you be able to submit a PR fixing it?

I could give it a shot.

0reactions
ddayguerrerocommented, May 14, 2020

Took at stab at resolving this. In fact, I believe my changes caused this type error. Hope you don’t mind!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found