table icon indicating copy to clipboard operation
table copied to clipboard

Incorrect example for custom column metadata declaration file

Open tar-aldev opened this issue 2 years ago • 5 comments

Describe the bug

If I create tanstack-table.d.ts file under types/ folder, it doesn't work and column meta is still not typed (it is of type unknown to be precise`)

Your minimal, reproducible example

https://tanstack.com/table/v8/docs/api/core/column-def#meta

Steps to reproduce

  1. Follow the example https://tanstack.com/table/v8/docs/api/core/column-def#meta
  2. Use
declare module '@tanstack/table-core' {
  interface ColumnMeta {
    // filterType: CustomFilterType | StandardFilterType;
    className: string;
  }
}

Expected behavior

types should work and column.meta should be typed, with className property.

How often does this bug happen?

Every time

Screenshots or Videos

Screenshot 2023-11-11 at 11 18 14

Platform

MacOS

react-table version

^8.10.7

TypeScript version

5.1.3

Additional context

It all works fine if I change it to this:

declare module '@tanstack/react-table' {
  interface ColumnMeta {
    // filterType: CustomFilterType | StandardFilterType;
    className: string;
  }
}

So could be jsut a mistake in documentation?

Terms & Code of Conduct

  • [X] I agree to follow this project's Code of Conduct
  • [X] 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.

tar-aldev avatar Nov 11 '23 09:11 tar-aldev

~UPD: it seems to fix the problem during runtime, but not during build time.~ ~When building the app, it gives~

 Property 'className' does not exist on type 'ColumnMeta<TableData, unknown>'.

It was related to the project structure. But I guess making this work for monorepo setup with smth like nx, will be a pain. Becaue you'll need to include types file into your tsconfig.json in app/ and then in every lib where you use table.

tar-aldev avatar Nov 13 '23 17:11 tar-aldev

@tar-aldev I got the same issue. How do you include the types file in tsconfig?

m3Lith avatar Dec 19 '23 13:12 m3Lith

@tar-aldev I got the same issue. How do you include the types file in tsconfig?

@tar-aldev ?

amocarski avatar Apr 26 '24 11:04 amocarski

So, there was an nx lib called table, there I had a file called tanstack-table.d.ts. Like this

table/
-- src/
---- types/
------ tanstack-table.d.ts

So for that lib it works already.

For all other libs, I added this into tsconfig.lib.json

So e.g. there is another lib users like

users/
-- tsconfig.lib.json
//  tsconfig.lib.json
{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "../../../../dist/out-tsc",
    "types": [
      "node",
      "@nx/react/typings/cssmodule.d.ts",
      "@nx/react/typings/image.d.ts",
      "next",
      "@nx/next/typings/image.d.ts"
    ]
  },
  "exclude": [
    ...
  ],
  "include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx", "../../../table/src/types"]
}

As I said, it's far from perfect, but I couldn't find a better way.

tar-aldev avatar Apr 26 '24 16:04 tar-aldev

Don't use table core. Specify which framework adapter you have installed.

KevinVandy avatar Apr 26 '24 16:04 KevinVandy