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

Getting type instantiation error #4224

Closed
2 tasks done
Slate245 opened this issue Jul 26, 2022 · 32 comments · Fixed by #4262
Closed
2 tasks done

Getting type instantiation error #4224

Slate245 opened this issue Jul 26, 2022 · 32 comments · Fixed by #4262

Comments

@Slate245
Copy link

Describe the bug

Hi, I'm still getting used to the library and most likely am doing something wrong.

Still, I want to use internationalized strings as headers in some of my columns. The compiler throws TS2589 error: Type instantiation is excessively deep and possibly infinite, pointing to a place where i call my translation function, which return simple string, not a deep literal type.

Curiously, when I replace the call with a simple string, the error moves to accessor function for this column.

ColumnDef for this column looks something like this:

columnHelper.accessor((transaction) => DateTime.fromJSDate(transaction?.created_at).toUTC(), {
	cell: (props) => (
		<Text title={props.getValue().toRelativeCalendar() ?? ""}>
			{props.getValue().toLocaleString(DateTime.DATETIME_SHORT_WITH_SECONDS)}
		</Text>
	),
	id: "created_at",
	header: t("sections.main.transactions.items.created_at"),
}),

I'm sorry I can't provide reproducible example, because I feel the problem is really project-dependant. I'm creating this issue asking mostly for answers on how to tame inferrance in tanstack-table, so I can avoid similar problems

Your minimal, reproducible example

no link

Steps to reproduce

  1. Define columns in a memo, providing a call to t function from react-18next as a header of a column.
  2. Try to compile the app

Expected behavior

I expect the app to compile correctly

How often does this bug happen?

Sometimes

Screenshots or Videos

No response

Platform

Linux

react-table version

v8.3.3

TypeScript version

v4.4.2

Additional context

No response

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
@tannerlinsley
Copy link
Collaborator

tannerlinsley commented Jul 26, 2022 via email

@spfoos
Copy link

spfoos commented Jul 26, 2022

I'm facing this as well (I think):

TS2589: Type instantiation is excessively deep and possibly infinite.

It's on columnHelper.accessor

@tannerlinsley
Copy link
Collaborator

I’ll need something reproducible to debug :/

@Slate245
Copy link
Author

It may happen due to some project-specific stuff. Because I tried adding {incremental: false} to tsconfig and the error went away. Even after I reverted tsconfig back to it's original state 😕.

@dcworldwide
Copy link

dcworldwide commented Aug 1, 2022

This issue began after 8.2.6. 8.2.6 is the latest version we are able to run for the time being.

A reduced example below. Prefer the ColumnDef syntax over the newly introduced Helper.

        const columns = React.useMemo<ColumnDef<Order>[]>(() => {

        let orderColumns: ColumnDef<Order>[] = []
        let commissionColumns: ColumnDef<Order>[] = []

        orderColumns.push({
            header: t("Id"),
            accessorKey: "orderRefId",
            size: 80,
            cell: props => {
                let o = props.row.original
                return <Link component={RouterLink} to={`/dashboard/${o.sId}/o/${o.id}`}>{o.orderRefId}</Link>
            }
        })

        commissionColumns.push({
            header: t("Paid Date"),
            accessorKey: "paymentPaidAt",
            minSize: 120,
            cell: props => {
                let o = props.row.original
                let paidAt = o.paymentPaidAt && o.paymentStatus != PaymentStatus.Unpaid
                    ? formatDate(o.paymentPaidAt)
                    : "-"
                return <div>{paidAt}</div>
            }
        })
        
        let columns: ColumnDef<Order>[] = []

        if (opts.enableSelection) {
            columns.push(makeTableCheckboxColumn())
        }

        columns.push({
            header: t("Order"),
            columns: orderColumns
        })

        columns.push({
            header: t("Commission"),
            columns: commissionColumns
        })

        return columns

    }, [])

@tannerlinsley
Copy link
Collaborator

We just shipped new column helper types and better underlying column def types. Please give them a try and report?

@himself65
Copy link
Contributor

himself65 commented Aug 3, 2022

My project might face the same error. When I upgrade from 8.2.6 to 8.5.5. The typescript compiler (4.7.4) got into the infinite compilation.

@himself65
Copy link
Contributor

I think the error comes from in v8.3.0

@vemoo
Copy link

vemoo commented Aug 3, 2022

Minimal repro: https://codesandbox.io/s/react-table-repro-s2b796?file=/src/index.ts

It indeed started happening on 8.3.0

@himself65
Copy link
Contributor

@himself65
Copy link
Contributor

himself65 commented Aug 4, 2022

This error occurs again in v8.5.8

/cc @tannerlinsley

@himself65
Copy link
Contributor

Example

import { ColumnDef, createColumnHelper } from '@tanstack/react-table'

type Room = {
  id: string
  activated_at: Date
  expires_at: Date
  userId: string
  join_code: string
  room: Room
}

const columnHelper = createColumnHelper<Room>()

const defaultColumns: ColumnDef<Room, any>[] = [
  columnHelper.accessor('id', {
    header: 'ID',
    cell: info => info.getValue()
  })
]
TS2589: Type instantiation is excessively deep and possibly infinite.

@MagnesiumDev
Copy link

MagnesiumDev commented Aug 28, 2022

@tannerlinsley I get this error, Im on v8.5.11

@slouchymunchkin
Copy link

I also get this error on v8.5.11.

I've tried using my own interface and the same interface in @himself65 example above.

@himself65
Copy link
Contributor

I also get this error on v8.5.11.

I've tried using my own interface and the same interface in @himself65 example above.

I think if you apply this patch, the issue will be fixed

#4262

@Nirajn2311
Copy link

I'm still facing this issue in react-table:8.7.4

@rotciw
Copy link

rotciw commented Dec 28, 2022

Also facing the same issue in react-table:8.7.4

@its-monotype
Copy link

Me too, facing the same issue in react-table:8.7.4

@mjlikre
Copy link

mjlikre commented Feb 8, 2023

Facing this issue in react-table:8.7.6, wonder if they're going to fix it ...

@jrozbicki
Copy link
Contributor

jrozbicki commented Feb 9, 2023

I was surprised to see it happen in one of the projects only, but now I think it might be connected to typescript version: I had 4.1.6 fixed in project, bump to latest and error went away 🎉

const columns = [ch.accessor("currency", {})];
-----------------------^ When I checked (hovered over) this, with 4.1.6 I saw never

accessor: <"currency", never>(accessor: "currency", column: IdentifiedColumnDef<TransportLineItem, never>) => ColumnDef<TransportLineItem, never>

and now with 4.9.5

(property) accessor: <"currency", string>(accessor: "currency", column: IdentifiedColumnDef<TransportLineItem, string>) => ColumnDef<TransportLineItem, string>

Edit: I forgot to mention that I haven't really had exactly the same case as OP, my data interface don't have circular dependency inside like:

type Room = {
  id: string
  room: Room
}

@its-monotype
Copy link

its-monotype commented Feb 9, 2023

import { createColumnHelper } from '@tanstack/react-table';

interface Dog {
  name: string;
  owner: Owner;
}

interface Owner {
  name: string;
  dog: Dog;
}

const columnHelper = createColumnHelper<Dog>();

const columns = [
  columnHelper.accessor('name', { // ts(2589): Type instantiation is excessively deep and possibly infinite.
    header: 'Name',
  }
]

https://codesandbox.io/s/tanstack-table-issues-4224-u92zmn?file=/src/App.tsx

Is it possible to fix it?

TS v4.9.3 in CodeSandbox and also I tried the same in VSCode with TS v4.9.5 and error still exists

@aoneahsan
Copy link

do we have a solution for this error???
image
image
using "@tanstack/react-table": "^8.7.9",

@AllenElguira16
Copy link

I have an issue where if I put a type like FileList, it will cause the the ts(2589) issue

With FileList
image
image

string only

image
image

@mosnicholas
Copy link

I still see this error too on the latest typescript and react-table :( anyone have a good solution?

@its-monotype
Copy link

Any updates?

@OkancanCosar
Copy link

any updates?

@uncvrd
Copy link

uncvrd commented May 24, 2023

Just wanted to report I sorta naively thought I could add a complex object in to the column helper and it straight up breaks TS across my entire project when I do so.

For example, I had a table I wanted to display Stripe Charges on. So I tried to do const helper = createColumnHelper<Stripe.Charge>(). And this causes VS Code to infinitely display the loading... prompt when hovering over an element on any file afterwards!

For now I am just creating temporary DTOs with the props that I actually need

@connorlindsey
Copy link

Also seeing this on 8.8.5 with the following (abbreviated) example. If I change ObjectId to be string, the ts error goes away so something to do with larger nested types maybe.

interface Patient {
    _id: ObjectId // from Mongoose
    ... other properties
}

const columnHelper = createColumnHelper<Patient>()
const columns = [
  columnHelper.accessor("name", {
    header: "Patient Info",
    cell: (info) => <span className="font-semibold text-gray-900">{info.getValue()}</span>,
  }),
]

@akshay-nm
Copy link

Simple objects are working fine. Recursive nested types break.

@benzara-tahar
Copy link

Having the same issue with 8.9.1
image

@its-monotype
Copy link

@tannerlinsley @KevinVandy Please help

@yarinsa
Copy link

yarinsa commented Oct 5, 2023

Please help :)

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 a pull request may close this issue.