Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property 'children' does not exist on type 'IntrinsicAttributes....' #88

Open
pmoieni opened this issue May 1, 2022 · 10 comments
Open

Comments

@pmoieni
Copy link

pmoieni commented May 1, 2022

I just upgraded my project from react 17 to react 18 and now I'm getting this error.

TS2769: No overload matches this call.
Overload 1 of 2, '(props: DraggableProps | Readonly): Draggable', gave the following error.
Type '{ children: ReactNode; key: number; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly'.
Property 'children' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly'.
Overload 2 of 2, '(props: DraggableProps, context: any): Draggable', gave the following error.
Type '{ children: ReactNode; key: number; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly'.
Property 'children' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly'.

this is my code:

function ReorderList({ items }: props) {
  const [allItems, setAllItems] = useState(items);

  return (
    <div className="reorder-list">
      <Container
        lockAxis="y"
        dragClass="reorder-list-dragging"
        dragHandleSelector=".reorder-list-handle"
        onDrop={(event) => setAllItems(applyDrag(allItems, event))}
      >
        {allItems.map((item, idx) => {
          return <Draggable key={idx}>{item}</Draggable>;
        })}
      </Container>
    </div>
  );
}
@pmoieni pmoieni changed the title Property 'children' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Draggable> & Readonly<DraggableProps>' Property 'children' does not exist on type 'IntrinsicAttributes....' May 1, 2022
@SerhiyDemchuk
Copy link

SerhiyDemchuk commented May 9, 2022

have you solved it? Container and Droggable have a prop called render. Move each component's children to this prop This is a rewritten smooth-dnd-demo.
<div className="card-scene"> <Container orientation="horizontal" onDrop={this.onColumnDrop} dragHandleSelector=".column-drag-handle" dropPlaceholder={{ animationDuration: 150, showOnTop: true, className: 'cards-drop-preview', }} render={() => ( <div> {this.state.scene.children.map((column: any) => { return ( <Draggable key={column.id} render={() => ( <div className={column.props.className}> <div className="card-column-header"> <span className="column-drag-handle">&#x2630;</span> {column.name} </div> <Container {...column.props} groupName="col" onDragStart={e => console.log('drag started', e)} onDragEnd={e => console.log('drag end', e)} onDrop={e => this.onCardDrop(column.id, e)} getChildPayload={index => this.getCardPayload(column.id, index) } dragClass="card-ghost" dropClass="card-ghost-drop" onDragEnter={() => { console.log('drag enter:', column.id); }} onDragLeave={() => { console.log('drag leave:', column.id); }} onDropReady={p => console.log('Drop ready: ', p)} dropPlaceholder={{ animationDuration: 150, showOnTop: true, className: 'drop-preview', }} dropPlaceholderAnimationDuration={200} render={() => ( <div> {column.children.map((card: any) => { return ( <Draggable key={card.id} render={() => ( <div {...card.props}> <p>{card.data}</p> </div> )} /> ); })} </div> )} /> </div> )} /> ); })} </div> )} /> </div>

However, now I have errors in the console.

@pmoieni
Copy link
Author

pmoieni commented May 9, 2022

@SerhiyDemchuk I'm still getting the same error

<Container
        lockAxis="y"
        dragClass="reorder-list-dragging"
        dragHandleSelector=".reorder-list-handle"
        onDrop={(event) => setAllItems(applyDrag(allItems, event))}
        render={() => (
          <>
            {allItems.map((item, idx) => {
              return <Draggable key={idx}>{item}</Draggable>;
            })}
          </>
        )}
      />

@SerhiyDemchuk
Copy link

@pmoieni do the same to Draggabe children, the component also has the prop "render"

@pmoieni
Copy link
Author

pmoieni commented May 9, 2022

@SerhiyDemchuk thanks. Now it's working.

<Container
        lockAxis="y"
        dragClass="reorder-list-dragging"
        dragHandleSelector=".reorder-list-handle"
        onDrop={(event) => setAllItems(applyDrag(allItems, event))}
        render={() => (
          <>
            {allItems.map((item, idx) => {
              return <Draggable key={idx} render={() => <>{item}</>} />;
            })}
          </>
        )}
      />

@SerhiyDemchuk
Copy link

@pmoieni do you have any errors in the console? Because despite I have no errors in IDE, I don't see any data to be rendered

@pmoieni
Copy link
Author

pmoieni commented May 11, 2022

@SerhiyDemchuk I thought when the error is gone everything should work. I have lots of errors in the console and just a blank screen. someone should update the documentation.

image

@MSSPL-KamalenduGarai
Copy link

Hi, is there any update on this cause I am having the same issue.

@BahaMagi
Copy link

BahaMagi commented Aug 1, 2022

If someone is still having that problem: I think its only a type issue where the components were not declared in a way that allows them to have child components. We only came across this when we updated typescript at some point.

We wrote a patch for it. The Draggable and Container components extend the incorrect type (e.g. in Draggable.d.ts)

declare class Draggable extends Component<DraggableProps> {

rather than

declare class Draggable extends Component<PropsWithChildren<DraggableProps>> {

Here is the patch file we used to fix it for us:

diff --git a/dist/src/Container.d.ts b/dist/src/Container.d.ts
index cdd0c03b8744ce35af905b5d5ce867f725f299b8..1786963d81768adc7b0fc4ac2909bbd690aac291 100644
--- a/dist/src/Container.d.ts
+++ b/dist/src/Container.d.ts
@@ -1,11 +1,11 @@
-import React, { Component, CSSProperties } from 'react';
+import React, { Component, CSSProperties,PropsWithChildren } from 'react';
 import PropTypes from 'prop-types';
 import { ContainerOptions, SmoothDnD } from 'smooth-dnd';
 interface ContainerProps extends ContainerOptions {
     render?: (rootRef: React.RefObject<any>) => React.ReactElement;
     style?: CSSProperties;
 }
-declare class Container extends Component<ContainerProps> {
+declare class Container extends Component<PropsWithChildren<ContainerProps>> {
     static propTypes: {
         behaviour: PropTypes.Requireable<string>;
         groupName: PropTypes.Requireable<string>;
diff --git a/dist/src/Draggable.d.ts b/dist/src/Draggable.d.ts
index 7ddbb5b3b13d1ea61c59a2ced1205afdbc68b647..9783d0fc33f10b6a3944b17bbe6b2c6a0e9fc6f8 100644
--- a/dist/src/Draggable.d.ts
+++ b/dist/src/Draggable.d.ts
@@ -1,10 +1,10 @@
-import React, { Component } from 'react';
+import React, { Component, PropsWithChildren } from 'react';
 import PropTypes from 'prop-types';
 export interface DraggableProps {
     render?: () => React.ReactElement;
     className?: string;
 }
-declare class Draggable extends Component<DraggableProps> {
+declare class Draggable extends Component<PropsWithChildren<DraggableProps>> {
     static propsTypes: {
         render: PropTypes.Requireable<(...args: any[]) => any>;
         className: PropTypes.Requireable<string>;

Can just run yarn patch yourself or copy this file into .yarn/patches . Dont forget to update the package.json with the patch

"react-smooth-dnd": "patch:react-smooth-dnd@npm:0.11.1#../.yarn/patches/react-smooth-dnd-npm-0.11.1-2550ef032f.patch",

@DoctorDib
Copy link

Can confirm that adding extends Component<PropsWithChildren<DraggableProps>> and extends Component<PropsWithChildren<ContainerProps>> in there respected places does seem to fix the issue. Do we know when this fix / patch will be applied to the main branch?

@MSSPL-KamalenduGarai
Copy link

MSSPL-KamalenduGarai commented Aug 3, 2022

While suggested patch did work, a patched version will be lifesaver for many of us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants