Skip to content

Conversation

@Ben-Ho
Copy link
Contributor

@Ben-Ho Ben-Ho commented Dec 16, 2025

Description

Idea to remove as cast in data-grid. Note: in my application code I had to make all props optional for typescript to stop complaining

@Ben-Ho Ben-Ho requested a review from johnnyomair December 16, 2025 12:55
@Ben-Ho Ben-Ho self-assigned this Dec 16, 2025
};

function ProductsGridToolbar({ exportApi, selectionModel }: ProductsGridToolbarProps) {
const ProductsGridToolbar: React.JSXElementConstructor<GridSlotProps["toolbar"] & ProductsGridToolbarProps> = ({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this explicit type definition here better than the as cast? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know as does disable any check. this kind of definition provides more type-safety. If the function is defined differently a typescript error is thrown for initializing the data-grid.

And as mentioned in the description in my application I needed to change the additional props to optional. I don't know why this wasn't necessary here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Module augmentation solution worked in this file, but resulted in issues in an other file. also I didn't found a solution for local module augmentation only, so augmented fields are also "available" in other grid-components.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

module augmentation is always global, I was thinking about something like that:

type ToolbarProps = PropsFromSlot<GridSlots['toolbar']> & ProductsGridToolbarProps;

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

Successfully merging this pull request may close these issues.

4 participants