Skip to content

Add typescript docs #1564

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

Merged
merged 2 commits into from
Oct 9, 2019
Merged

Add typescript docs #1564

merged 2 commits into from
Oct 9, 2019

Conversation

ggascoigne
Copy link
Contributor

This is tied to the type implementation found in #1535.

I'm more than happy if this gets merged into that branch before merging, or whatever's convenient :)

@ggascoigne ggascoigne mentioned this pull request Oct 2, 2019
@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 2, 2019

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit a5e2a7d:

Sandbox Source
hardcore-gates-glccg Configuration

@simPod
Copy link

simPod commented Oct 4, 2019

When defining

export interface TableOptions<D extends object>
  extends UsePaginationOptions<D>,
    UseSortByOptions<D> {}

How to use it then?

Should I also redefine

  export function useTable<D extends object = {}>(
    options: TableOptions<D>,
    ...plugins: PluginHook<D>[]
  ): TableInstance<D>;

?

@ggascoigne
Copy link
Contributor Author

@simPod You don't have to do anything.

I know, it took me a while to get my head around what's happening. All of the type definitions are global, so by extending the definitions of say TableOptions, we've updated them everywhere, including in the pre-existing definitions.

@simPod
Copy link

simPod commented Oct 5, 2019

Right, makes sense!

But what if... I use different tables with different plugins? Eg. table A uses sorting and table B uses pagination. Then I should type them separately

export interface TableOptionsSorted<D extends object> extends UseSortByOptions<D> {} // table A
export interface TableOptionsPaginated<D extends object> extends UsePaginationOptions<D> {} // table B

@ggascoigne
Copy link
Contributor Author

ggascoigne commented Oct 5, 2019 via email

@simPod
Copy link

simPod commented Oct 5, 2019

I was wondering that we could somehow allow to pass those custom types into useTable.
Eg. similar as in React's type FC<P = {}> = FunctionComponent<P>; where you can pass custom component props.

Not sure if doable tho, don't have any experience in designing such complex types.

export interface TableComposite<D extends object = {}> {
  value: D;
  options: TableOptions<D>;
  instance: TableInstance<D>;
  state: TableState<D>;
  column: Column<D>;
  columnInstance: ColumnInstance<D>;
  cell: Cell<D>;
  row: Row<D>;
}

...

useTable<TableComposite<MyValueType>>(...)

@stramel
Copy link
Contributor

stramel commented Oct 5, 2019

@simPod This has already been discussed and explored.
#1535 (comment)
#1535 (comment)

Unless you're speaking to extending each type at each instance and pass that to the type. Which I'm unsure if we would run into a similar situation.

@tannerlinsley
Copy link
Collaborator

There have been changes to the API around useTableState. Please see the latest commits and release to get up to date.

UseGroupByCellProps<D>,
UseRowStateCellProps<D> {}

export interface Row<D extends object = {}>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to add Omit<UseTableRowProps<D>, 'state'> for I'm using getRowProps and cells on Row. Also had to omit state: object because it's already in UseRowStateRowProps as state: UseRowStateLocalState<D>.

Suggested change
export interface Row<D extends object = {}>
export interface Row<D extends object = {}> extends UseExpandedRowProps<D>,
UseGroupByRowProps<D>,
UseRowSelectRowProps<D>,
Omit<UseTableRowProps<D>, 'state'>,
UseRowStateRowProps<D> {
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed this as well, and raised this on #1535, though I'm failing to find the comment right now. I'll add it to the list again.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Everything else works for me (though I have only one table for v7). Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to determine which state is correct.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

state only appears to be on row if you use useRowState plugin hook. In which, it forks the key rowState out of state.

@ggascoigne
Copy link
Contributor Author

@stramel I think that this addresses your comment from the other PR.

@ggascoigne
Copy link
Contributor Author

@stramel @tannerlinsley - is it worth merging this before the next release?

@stramel
Copy link
Contributor

stramel commented Oct 9, 2019

I think so

@tannerlinsley
Copy link
Collaborator

Okie dokie!

@tannerlinsley tannerlinsley merged commit cee24c7 into TanStack:master Oct 9, 2019
@ggascoigne ggascoigne deleted the docs branch October 9, 2019 21:42
@tannerlinsley
Copy link
Collaborator

Released!

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 this pull request may close these issues.

4 participants