Skip to content

Use accessor type to narrow value type in createDataColumn - #3788

Merged
tannerlinsley merged 1 commit into
TanStack:alphafrom
david-crespo:fix-col-value-inference
Apr 1, 2022
Merged

Use accessor type to narrow value type in createDataColumn#3788
tannerlinsley merged 1 commit into
TanStack:alphafrom
david-crespo:fix-col-value-inference

Conversation

@david-crespo

@david-crespo david-crespo commented Apr 1, 2022

Copy link
Copy Markdown
Contributor

I think 5636cf4 broke inference of the value type based on the accessor. The values are stuck at the default unknown.

const table = createTable<Disk>()

const columns = table.createColumns([
  table.createDataColumn('name', {
    header: 'Name',
    cell: ({ value }) => <div>{value}</div>, // <-- value has type unknown
  }),
  table.createDataColumn((d) => d.state.state, {
    id: 'status',
    header: 'Status',
    cell: ({ value }) => <DiskStatusBadge status={value} />, // also unknown
  }),
])

I tested this fix in my project by modifying the copy inside node_modules and it did bring back the inference, so it seems to be the right idea even though it's ugly. All I really did was bring back what was going on before the breaking commit:

https://github.com/TanStack/react-table/blob/f27720c53b581521aceac3ad76c5a6d4fa1f18c3/packages/react-table/src/createTable.tsx#L103-L150

@vercel

vercel Bot commented Apr 1, 2022

Copy link
Copy Markdown

@david-crespo is attempting to deploy a commit to the Tanstack Team on Vercel.

A member of the Team first needs to authorize it.

@tannerlinsley
tannerlinsley merged commit ee4631a into TanStack:alpha Apr 1, 2022
@david-crespo
david-crespo deleted the fix-col-value-inference branch April 1, 2022 15:17
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.

2 participants