Skip to content
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

Add additional type-casts for React nodes #7402

Merged
merged 1 commit into from
Jun 15, 2022

Conversation

jonkoops
Copy link
Contributor

Since React 18 has stricter types than before some type-casts need to be added and expanded in order for the code to compile successfully.

Needed to land #7142

@jonkoops jonkoops mentioned this pull request May 11, 2022
20 tasks
@patternfly-build
Copy link
Contributor

patternfly-build commented May 11, 2022

@nicolethoen nicolethoen requested review from tlabaj and nicolethoen May 17, 2022 18:15
@jonkoops
Copy link
Contributor Author

@nicolethoen @tlabaj could this get reviewed and merged? I'd like to rebase the React 18 PR on top.

@@ -271,16 +275,20 @@ export class DualListSelector extends React.Component<DualListSelectorProps, Dua
this.setState(prevState => {
const movedOptions =
prevState.availableTreeFilteredOptions ||
flattenTreeWithFolders(prevState.availableOptions as DualListSelectorTreeItemData[]);
flattenTreeWithFolders((prevState.availableOptions as unknown) as DualListSelectorTreeItemData[]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious. Why unknown here and not any?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The unknown keyword still allows a stricter subset of type checking, whereas any disables all checks. But in this case I used unknown as it was the recommendation by the compiler.

@jonkoops jonkoops requested a review from tlabaj June 7, 2022 13:44
Copy link
Contributor

@nicolethoen nicolethoen left a comment

Choose a reason for hiding this comment

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

So im realizing that you're needing to cast these list as unknown since the chosenOptions and availableOptions props are both typed as React.ReactNode[] | DualListSelectorTreeItemData[].

It seems as though, since the tree feature was added later, we could tighten the typing of these various lists of options used throughout the component to avoid using the 'unknown' casting. Unless casting to unknown was something recommended as part of the migration to react 18 and is a fine solution. WDYT?

@tlabaj
Copy link
Contributor

tlabaj commented Jun 13, 2022

@nicolethoen dual list selector is still Beta so we can make improvements to API that are "breaking"

I do not know if that is blocker for this PR though. we could open a follow up issue to address that.

@jonkoops any thought on this?

@jonkoops
Copy link
Contributor Author

Sorry for the late response, I have been focused on some other projects so I haven't had the time to get back to this.

It seems as though, since the tree feature was added later, we could tighten the typing of these various lists of options used throughout the component to avoid using the 'unknown' casting.

Yes, I think it makes total sense to re-work these types. Ideally there would never be any unknown or any types present in the project. This is however not always possible and in this case I wanted to avoid a large refactor to this component.

I do not know if that is blocker for this PR though. we could open a follow up issue to address that.

Agreed, let's open up an issue for this. Especially if this is still a 'beta' feature I think it makes sense to stabilize this before making it set in stone.

I think we can merge this as-is so I can continue creating new PRs to help with the React 18 migration. WDYT @nicolethoen @tlabaj?

@jonkoops jonkoops requested a review from nicolethoen June 13, 2022 21:32
Copy link
Contributor

@tlabaj tlabaj left a comment

Choose a reason for hiding this comment

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

LGTM

@tlabaj
Copy link
Contributor

tlabaj commented Jun 14, 2022

I opened this follow up issue for the dual list selector
#7548

@nicolethoen nicolethoen merged commit c0526f8 into patternfly:main Jun 15, 2022
@jonkoops jonkoops deleted the cast-react-node branch June 16, 2022 13:38
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