Context:
Our team is currently working on a UI component library using React and TypeScript, leveraging react-table
for our table component. This library has been packaged as an npm module and is being utilized in various projects within our organization.
To enhance the TypeScript support for our library users, I have set up the types according to the instructions provided in the documentation of @types/react-table
within a file named react-table-config.d.ts
. Additionally, I have introduced a new type called CustomColumn
, which builds upon the existing Column
definition by enabling nested string accessors for improved data recognition by TypeScript (e.g., identifying foo.bar
as a valid string accessor for the table data).
Goal:
My primary aim is to provide this advanced TypeScript support to our library consumers, especially making it possible for them to utilize the CustomColumn
.
Problem:
However, upon installing the library package in another project, the configured types for react-table
seem to be inaccessible as they are not included in the package at all.
I am exploring ways to avoid the need for a separate typings package, although that could potentially resolve the issue.
What I've tried so far:
I found it surprising that this solution did not work immediately, considering we were able to extend the Emotion-Theme successfully through a similar extension mechanism for type declarations. To make the custom theme accessible to library users, we simply renamed emotion.d.ts
to emotion.ts
.
Similarly, I attempted a comparable method with react-table-config.d.ts
(renamed to
react-table-config.ts</code), but encountered numerous TypeScript errors due to inconsistencies between the recommended usage of <code>Record<,>
and the object-centric generics used in the actual DefinitelyTyped type definitions.
Despite resolving these type conflicts and ensuring that react-table-config.d.ts
is generated and included in the package via transpilation, my custom types remain underutilized when applied in the external project.
Other strategies I have tested include:
- Adjusting
compilerOptions.typeRoots
in thetsconfig.json
of the component library - Modifying
compilerOptions.paths
in thetsconfig.json
of the dependent library - Altering imports in an effort to transform
react-table-config.d.ts
into an ambient module, following guidance from this response - Including
in the/// <reference path="../../@types/react-table-config.ts"/>
index.ts
file where I attempt to exportCell
andCustomColumn
I am eager to comprehend why this approach is ineffective, particularly given that the Theme override for Emotion functions as expected. One key difference I noted is that Emotion inherently supports TypeScript, eliminating the need for a separate typings package.
If providing specific code snippets would aid in troubleshooting, I am willing to share them if feasible. Nonetheless, since this issue appears systemic in nature, I prefer not to indiscriminately disclose code snippets.