question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript Discussion

See original GitHub issue

Hi all,

I’d like to start by saying thank you to all the maintainers and contributors of this package 💯 and also apologies for not using the issue template format, wasn’t quite sure if this was a bug or a feature request.

I’ve been trialling the v7 branch, and overall its really really impressive 🙌 The only part that seemed a little … lacking was the Typescript types. This was not a huge issue, as I was able to create my own types file that the compiler merges with the types provided by react-table (using declaration merging)

I noticed that beta 12 has recently been released, and I updated (from beta 10). Unfortunately, it seems that the situation has somewhat worsened from a developer experience perspective. I’m assuming the changes were made in order to better handle the fact that any number of plugin hooks might be specified by a user. However, these changes seem to have come at the cost of requiring users to include a custom types file in their projects (which is a little unusual, even for Typescript projects).

In an ideal world, it’d be great to see react-table written natively in Typescript to avoid situations where the code and types are not in sync, but I do understand that might not be what the maintainers/contributors want. That said, the procedure in beta 12 seems like it could be improved, and I’m happy to help 😄 I’m including my additions to the types file from beta 10 that mostly fixed the plugin issues, as well as adding a few other missing types. There are some definite improvements in the beta 12 types, so it’d be good to see if we can find some middle ground.

import {
  Row,
  TableInstance,
  TableOptions,
  useGroupBy,
  useFilters,
  useSortBy,
  useExpanded,
  usePagination,
  useRowSelect,
  useRowState,
  useColumnOrder,
  useBlockLayout,
  useAbsoluteLayout,
  useResizeColumns,
  Column,
} from "react-table";

declare module 'react-table' {
  export interface TableInstance<D = {}> extends TableOptions<D> {
    getTableBodyProps: (userProps?: any) => any
    selectedFlatRows: Row<D>[]
  }

  export interface HeaderColumn<D> {
    disableFilters?: boolean;
  }

  export interface EnhancedColumn<D>
    extends Omit<Column<D>, 'columns'>,
      TableInstance<D> {
    canFilter?: boolean
  }

  export interface UsePaginationValues<D = {}> {
    pageOptions: number[]
  }

  export type Plugin<D> = useGroupBy<D> |
    useFilters<D> |
    useSortBy<D> |
    useExpanded<D> |
    usePagination<D> |
    useRowSelect<D> |
    useRowState<D> |
    useColumnOrder<D> |
    useBlockLayout<D> |
    useAbsoluteLayout<D> |
    useResizeColumns<D>

  export function useTable<D = {}, P = Plugin<D>>(
    props: TableOptions<D>,
    ...plugins: P[]
  ): TableInstance<D> & ReturnType<typeof P>

  export function useRowSelect<D = {}>(
    props: TableOptions<D>
  ): TableOptions<D>
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:18
  • Comments:66 (14 by maintainers)

github_iconTop GitHub Comments

113reactions
tannerlinsleycommented, Nov 18, 2020

I hear you, and I even tried to do that at the start of 2020. However, I quickly learned a few things:

  • Incrementally adding TS to a JS project like you said is easy to start, but quickly results in a massive amount of anys and unknowns. This is fine, but not in the long run. At some point, the work/time will be better spent in a rewrite.
  • With public gradual migration, it’s inevitable that you will eventually have to make breaking changes to get rid of the untypable dynamisms in the library to get full TS intellisense and holistically correct types. This isn’t a very good experience to have a public api that is always slowly, but constantly, breaking.
  • TypeScript is simple, but not easy. A library like this requires a massive amount of generics, a highly sophisticated plugin system with multiple plugin points (22+ actually) and a very rich I/O model that permeates just about every corner of the library.

With all of that said, you’ll be happy to know that I’m currently writing v8 natively in TypeScript. I assure you, it’s a beast, but it’s also awesome. Take it from me, with what I know about the internals and current API in v7, there’s no way to backport accurate types to v7 that will even come close to v8.

56reactions
tannerlinsleycommented, Aug 1, 2021

Still working actively on it.

Tanner Linsley On Jul 20, 2021, 8:22 AM -0600, Nubami SQReder @.***>, wrote:

Is there any updates on v8? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript Community Resources
Engage with your peers and ask questions about TypeScript using the tag 'typescript' ... Chat with other TypeScript users in the TypeScript Community...
Read more >
Discuss TypeScript - Tutorialspoint
Discuss TypeScript, TypeScript lets you write JavaScript the way you really want to. TypeScript is a typed superset of JavaScript that compiles to...
Read more >
Discussion of The Trouble with TypeScript - DEV Community ‍ ‍
This was not my experience with TypeScript at all. I consider type annotations a way to increase the expressiveness of my code.
Read more >
Example with Javascript only (no typescript) #4096 - GitHub
Hi,. I am using Next.js using only javascript , no typescript. In the currently available I found only ts examples, which I find...
Read more >
Discussing the over-engineering trap in TypeScript
Before I start the discussion of over-engineering in TypeScript, I want to give a basic overview of how JavaScript and more strongly-typed ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found