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

Wrong detailPanel prop signature when passing array of functions #455

Closed
tondi opened this issue Jan 12, 2022 · 4 comments
Closed

Wrong detailPanel prop signature when passing array of functions #455

tondi opened this issue Jan 12, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@tondi
Copy link
Contributor

tondi commented Jan 12, 2022

When passing array of functions to detailPanel prop, a typescript error is shown. It works well in runtime.

type RowData = { word: string };

const App = () => {
  const [data, setData] = useState(rawData);

  return (
    <MaterialTable<RowData>
      data={data}
      columns={columns}
      title="Starter Template"
      icons={tableIcons}
      // here:
      detailPanel={[
        (rowData) => ({
          render: () => <pre>{rowData.word}</pre> // Property 'word' does not exist on type '{ rowData: RowData; }'.ts(2339) error
        })
      ]}
    />
  );
};

rowData.word gives Property 'word' does not exist on type '{ rowData: RowData; }'.ts(2339)

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://codesandbox.io/s/material-table-starter-template-forked-yrup9?file=/src/index.tsx
  2. See error in detailPanel definition
  3. Expand row
  4. Notice that data is properly rendered

Screenshots
image
image

We probably want no ts error when using (rowData: RowData) => ...

--- a/types/index.d.ts
+++ b/types/index.d.ts
@@ -28,7 +28,7 @@ export interface MaterialTableProps<RowData extends object> {
     | (({ rowData }: { rowData: RowData }) => React.ReactNode)
     | (
         | DetailPanel<RowData>
-        | (({ rowData }: { rowData: RowData }) => DetailPanel<RowData>)
+        | (( rowData: RowData ) => DetailPanel<RowData>)
       )[];
   editable?: {
     isEditable?: (rowData: RowData) => boolean;

or a change in detailPanel to make it really return { rowData: RowData }

@tondi tondi added the bug Something isn't working label Jan 12, 2022
@Domino987
Copy link
Contributor

Rowdata needs to be the type of the row and not if the column. Rowdata does not contain Word, so it's correct. If you update your type to include word it will work.

@tondi
Copy link
Contributor Author

tondi commented Jan 12, 2022

Sorry, it should be type RowData = { word: string }. I created this example quickly.
Here you can see screenshot with RowData updated to correct type, and that the error persists:

image

https://codesandbox.io/s/material-table-starter-template-forked-vbd27?file=/src/index.tsx:496-529

@tondi
Copy link
Contributor Author

tondi commented Jan 21, 2022

@Domino987 Do you want me to submit a PR with the proposed fix?

@Domino987
Copy link
Contributor

I am currently looking into it but sure!

tondi added a commit to tondi/material-table-core that referenced this issue Jan 27, 2022
…e when detailPanel is an array of callbacks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants