frustration trying to get ColumnMeta to work properly #5614
Replies: 1 comment
-
alright so at least for my particular use case, i got it figured out. Has nothing to do with tanstack, just a more nuanced understanding of how typescript works was needed. because im in a monorepo (NX), i found success in doing exactly what ive done above in a typed.d.ts file in the root of a library, importing it into the tsconfig.libs.json file (auto generated when using nx to create the libraries, for others this would just be their root tsconfig.json file), and use as needed. Two gotchas are to ensure that you import tanstack in the definition file, and to ensure the generic types are the same as the ones defined in the tanstack lib itself... types.d.ts file /* eslint-disable @typescript-eslint/no-unused-vars */
import "@tanstack/react-table";
declare module "@tanstack/react-table" {
interface ColumnMeta<TData, TValue> {
type?: "numerical" | "display" | "text";
selectionType?: "single" | "multi";
}
} tsconfig.lib.json file {
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"types": [
"node",
"@nx/react/typings/cssmodule.d.ts",
"@nx/react/typings/image.d.ts",
"./types.d.ts" // << added here
]
},
"exclude": [
"**/*.spec.ts",
"**/*.test.ts",
"**/*.spec.tsx",
"**/*.test.tsx",
"**/*.spec.js",
"**/*.test.js",
"**/*.spec.jsx",
"**/*.test.jsx"
],
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
} |
Beta Was this translation helpful? Give feedback.
-
If someone could explain this to me like im five, that'd be swell. Ive been havin a dance off with this declaration stuff for the last 2 hours and im at my wits end.
this is my own ColumnMeta at the moment...
when i try to copy pasta the exact suggestion from the docs here, in a table.d.ts file...
nothing is inferred. anywhere. the createColumnHelper accepts anything thrown at its meta object, not the best DX at all but better than nothing and im forced to ignore the suggestion in the docs and roll my own ColumnMeta and cast in place where i need it to behave. for context this is within the context of an NX monorepo, dunno if that helps at all. what am i doing wrong?
Beta Was this translation helpful? Give feedback.
All reactions