This is a migrated thread and some comments may be shown as answers.

Passing custom props where Typescript is being used

1 Answer 302 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
SoH
Top achievements
Rank 1
Iron
Veteran
Iron
SoH asked on 23 Jul 2020, 10:14 AM

My custom component for a custom cell is created using Typescript:

1.import {GridCellProps} from '@progress/kendo-react-grid';
2. 
3.export class CustomCell extends React.Component<Readonly<GridCellProps>> {
4.    ...
5.}

I am trying to pass a custom prop to it: 

MyCustomCell = (props) => <CustomCell {...props} myProp={this.customData} />

But get the error:
Property 'myProp' does not exist on type 'Readonly<Readonly<GridCellProps>> & Readonly<{ children?: ReactNode; }>'.

How can I get past the TS constraint?

1 Answer, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 23 Jul 2020, 11:51 AM

Hello,

This is expected as myProp is not part of the GridCellProps interface.

This can be resolved by passing `any` to the props type instead of GridCellProps, as this is a custom cell and it is expected to have different props.

Using GridCellProps is not required in this case, and can be replaced with no issues.

If you still prefer to keep all GridCellProps, a new interface MyCustomCellProps can be done that will extend the GridCellProps and add the new props like myProp and more.

Regards,
Stefan
Progress Telerik

Tags
General Discussions
Asked by
SoH
Top achievements
Rank 1
Iron
Veteran
Iron
Answers by
Stefan
Telerik team
Share this question
or