Skip to content

Making Datagrid Generic #10595

Closed
Enhancement
@ogustavo-pereira

Description

@ogustavo-pereira

What you were expecting:
I'm getting this error

Conversion of type 'RecordType' to type 'MyGenericType' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.

And I believe it is bad practice to continue with the unkown for this case

What happened instead:

I'm not able to pass a generic to the datagrid so that it changes the record in rowClick and other functions.

Image

  1. If I try to pass the generic it says it doesn't accept it
  2. If I don't pass the generic the error in the row function still remains and I can't overwrite it without passing unknow

Steps to reproduce:

  1. Create any list screen
  2. Use RowClick and assign a record with "as"

Related code:
Datagrid.tsx / DatagridProps

export interface DatagridProps<RecordType extends RaRecord = any>
    extends Omit<TableProps, 'size' | 'classes' | 'onSelect'> {
    /**
     * The component used to render the body of the table. Defaults to <DatagridBody>.
     *
     * @see https://marmelab.com/react-admin/Datagrid.html#body
     */
    body?: ReactElement | ComponentType;

    /**
     * A class name to apply to the root table element
     */
    className?: string;

Other information:

Environment

  • React-admin version: 5.6.3
  • Last version that did not exhibit the issue (if applicable): 5.3.4
  • React version: 18.3.1
  • Browser: Chrome
  • Stack trace (in case of a JS error): N/A

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions