ctrlplusb / react-sizeme

Make your React Components aware of their width and height!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Typescript and SizeMeOptions: Property 'children' is missing but required in type 'SizeMeOptions"

bt-88 opened this issue · comments

commented

I have created a component that gets its width and height via SizeMe. The code below works perfectly.

class InternalGrid extends React.Component<GridProps & SizeMeProps>
{
   public render() {
      <div><span>{this.props.width}</span></div>
   }
}

export const Grid = withSize()(InternalGrid)

When I provide SizeMeOptions as below:

export const Grid = widthSize({ refreshRate: 100 })(InternalGrid)

It breaks with the following error:

Type error: Argument of type '{ refreshRate: number; }' is not assignable to parameter of type 'SizeMeOptions'.
  Property 'children' is missing in type '{ refreshRate: number; }' but required in type 'SizeMeOptions'.  TS2345

The type SizeMeOptions requires children of type children(props: SizeMeProps): JSX.Element;. I understand the error, but I can't seem to get to a solution.

commented

Update.

I have "solved" this, by adding a dummy lambda to children as follows:

export const Grid = withSize({ refreshRate: 100, children: (props) => (<div />)})(InternalGrid)

This has been fixed with latest publication of definitions. 👍