-
Notifications
You must be signed in to change notification settings - Fork 39
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
Improve Table typing #1514
Improve Table typing #1514
Conversation
…mns` from ColumnGroupInterface (to disallow multi-level headers)
…rties from the column object in the columns array
…re missing or incorrect
apps/storybook/src/Table.stories.tsx
Outdated
) satisfies NonNullable< | ||
TableProps<{ | ||
name: string; | ||
description: string; | ||
}>['onExpand'] | ||
>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we make some of these less verbose by doing this?
) satisfies NonNullable< | |
TableProps<{ | |
name: string; | |
description: string; | |
}>['onExpand'] | |
>; | |
) satisfies NonNullable<TableProps['onExpand']>; |
if the user needs additional type checking, they can add the extra data types, but shouldn't be required to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we make some of these less verbose by doing this?
234f4f8: I removed all such satisfies NonNullable<...>
that used { name: string; description; }
. But I didn't remove the ones that already use TableStoryDataType
or something similar because they were not too verbose. That way we can show some variations while still not being verbose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i also noticed that
state
isany
for some reason
Looks like this is happening when state
is assigned a type from react-table-types.ts
itself.
Because when I change it to some primitive type like string
or number
, the type of state is inferred correctly.
I haven't been able to find a fix so far, but just wanted to give a quick update while I am still searching for the fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized that this was happening because in Table.tsx
we were importing react-table
, instead of importing by path.
E.g. in Table.d.ts
generated by tsc using Table.tsx
- import type { CellProps, TableOptions, Row, TableState } from 'react-table';
+ import type { CellProps, TableOptions, Row, TableState } from../../react-table/react-table.js
Importing from react-table
from this file imports from the real react-table
package instead of from the path mentioned in paths
of tsconfig
.
I did this commit (7b4c2c8) to fix the above problem. I noticed quite a few type errors in Table.stories.tsx
. To avoid convoluting this PR, I reverted that commit and will fix the above issue in another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fine by me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! nice work, and everything seems to work much better now.
would be nice if you can remove outdated parts from PR description before merging.
Thanks!
Sounds good, updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No further comments from my side. LGTM 🌵
Edit: do we need wiki for these changes?
Added to the v3 migration guide: |
…ress of updating Table.stories.tsx
… In progress of updating Table.stories.tsx" This reverts commit 7b4c2c8.
See migration guide (section) to see how this PR affects you.
Changes
@types/react-table
. Instead, I merged the types from@types/react-table
with our custom types fromreact-table.config.ts
. The new file is calledreact-table.ts
./react-table
.react-table
. This is because of the following reason:@types/react-table
anymore, I addedpaths
to thecompilerOptions
initwinui-react/tsconfig.json
to point to ourreact-table-types.d.ts
for the types. This enables intellisense/type checking to work correctly without any import change./react-table
works only for new node versions. Thus,react-table.ts
is transpiled toreact-table.d.ts
and stored in the root folder so that this file is accessible to users with old node versions who cannot use theexports
map inpackage.json
and have to import by paths. (Improve Table typing #1514 (comment))object
(like in@types/react-table
), each row data now extendsRecord<string, unknown>
(like in our Table files (e.g. TextFilter))Table
: allow passing top-levelHeader
again #1072 that were meant to be temporary changes.tsconfig.react-table.json
to transpilereact-table.ts
toreact-table.d.ts
. This is used in@itwinui-react
'sbuild
anddev:types
scripts.@itwinui-react
'stest
is not split intoyarn test:types
(new) andyarn test:unit
(existing).yarn test:types
checks the types of all Table files (including unit tests, etc.) and not just the files that will be built using tsc.Testing
First, I ensured that the below long and convoluted type error when doing
[...] satisfies Column<DataType>[]
was fixed:react-table-types.test.tsx
to only verify that there were no type errors for some unique cases. This also ensures there are type errors where we expected them. No unit testing is done here.Table.story.tsx
.yarn test:types
scripts that rantsc --noEmit
(docs) on all Table files in itwinui-react (includingreact-table-types.test.tsx
), and alsoTable.stories.tsx
in storybook.Docs
I fixed all type errors in
Table.stories.tsx
. These fixes demonstrate how to usesatisfies
or sometimes provide types to the function parameters to solve type errors.I did not add anything to the website, because the Table doc page was not complete before this PR. When working on the Table page in the future, we can include info about this PR.
I updated
CONTRIBUTING.md
to mention that itwinui-react unit tests are now run usingyarn test:unit
instead ofyarn test
. I didn't mention aboutyarn test:types
as of now since this script only tests the types for Table files and not all files. But in the future PR that checks the types for all files, I will include info about this script.TODOs:
This PR:
Table -> Full
story's hover is working correctly.Table -> StatusAndCellIcons
story is loading correctly.react-table-types.d.ts
once again (Improve Table typing #1514 (comment))Separate PRs:
Table
: allow passing top-levelHeader
again #1072