Skip to content

Conversation

Tbhesswebber
Copy link
Contributor

@Tbhesswebber Tbhesswebber commented Mar 14, 2024

What does this PR do?

This PR fixes the TypeScript types for ListExtendedProps to align with the documentation.

Where should the reviewer start?

There isn't much to this PR. I would start with reading through #7160 and then pulling the code down to test in a development environment.

What testing has been done on this PR?

Migrated the tests to Typescript and modified the object children test

How should this be manually tested?

Use it in a development environment.

What are the relevant issues?

Closes #7160

Screenshots (if appropriate)

Screenshot of intellisense in VSCode Type inference works properly with this change in the types

Do the grommet docs need to be updated?

No, although I'm not sure what the type for the third argument should be based on the docs, so I left it a vague Record<string, any>

Should this PR be mentioned in the release notes?

No

Is this change backwards compatible or is it a breaking change?

Backwards compatible unless people leveraged module augmentation or similar to get around the issue.

Comment on lines -57 to +63
onClickItem?:
| ((event: React.MouseEvent) => void)
| ((event: { item?: ListItemType; index?: number }) => void);
onClickItem?: (
event: React.MouseEvent & { item: ListItemType; index: number },
) => void;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Based on a read-through of the code, the correct type is a function with the intersection of the event and what it gets modified with as the single argument

Comment on lines -79 to +83
p: React.PropsWithChildren<ListExtendedProps<ListItemType>>,
p: ListExtendedProps<ListItemType>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what was clobbering the type in such a weird way

<List data={data} paginate={{ background: 'red', margin: 'large' }} />
<List data={data} paginate={{ margin: 'large' }} />
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like background isn't actually a valid paginate prop

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good catch, I think removing the background here is fine

Comment on lines +557 to +558
if (!$element)
throw new Error('Cannot find element with id "alphaMoveDown"');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This short-circuits so that fireEvent doesn't get passed null

Comment on lines -630 to +634
action={(item, index) => (
action={(_, index) => (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was a lint error about unused arguments and the _ fixes that

@jcfilben jcfilben added the PRty Biweekly PR reviews by grommet team with hoping of closing such PRs label Mar 14, 2024
Comment on lines +46 to +50
children?: (
item: ListItemType,
index: number,
state?: { active: boolean },
) => any;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am getting a typescript error on the active prop if I try to do something like this: (item, index, {active}) => {}.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I misread the documentation - I thought the entire state object was optional rather than just the properties within. Fix incoming!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just ran into an issue - I modified the test to validate and it seems that it's actually the entire state object that is optional. Pinging on Slack for follow-up semi-synchronous conversation and will report back the decision for posterity's sake.

image

Copy link
Collaborator

Choose a reason for hiding this comment

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

Discussed offline, we are going to hold off on trying to support destructuring the active prop in the typescript definition. I think we can move forward with the types that are defined in this PR.

<List data={data} paginate={{ background: 'red', margin: 'large' }} />
<List data={data} paginate={{ margin: 'large' }} />
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good catch, I think removing the background here is fine

Copy link
Collaborator

@jcfilben jcfilben left a comment

Choose a reason for hiding this comment

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

Looks good!

@jcfilben jcfilben requested a review from taysea March 19, 2024 18:58
@britt6612 britt6612 self-requested a review March 25, 2024 23:17
@britt6612 britt6612 removed the PRty Biweekly PR reviews by grommet team with hoping of closing such PRs label Mar 27, 2024
@taysea taysea merged commit 72d0b62 into grommet:master Apr 10, 2024
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.

[TypeScript] List component types don't correctly support render props
4 participants