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

fix(cx): return a consistent string type #21

Merged
merged 2 commits into from
Oct 17, 2022
Merged

Conversation

Haroenv
Copy link
Contributor

@Haroenv Haroenv commented Oct 17, 2022

This has a downside that if you call cx with values that are all falsy, an empty class will be written, but upside that you can rely on string manipulation later if needed.

This changes the snapshot of highlight, but not the real life usage, as that's called with a string that definitely exists.

This isn't a breaking change in my opinion, as an empty className and no className act identical, and this solution is much simpler than #20 or changing all code related to classNames in InstantSearch to have every key optional (even if they actually aren't going to be undefined)

For reference, the classnames package is also typed to always return a string.

closes #20

This has a downside that if you call cx with values that are all falsy, an empty class will be written, but upside that you can rely on string manipulation later if needed.

This changes the snapshot of highlight, but not the real life usage, as that's called with a string that definitely exists.

This isn't a breaking change in my opinion, as an empty className and no className act identical, and this solution is much simpler than #20 or changing all code related to classNames in InstantSearch to have every key optional (even if they actually aren't going to be undefined)

For reference, the `classnames` package is also typed to always return a string.
Copy link
Member

@aymeric-giraudet aymeric-giraudet left a comment

Choose a reason for hiding this comment

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

I prefer this solution ! clsx also returns string no matter what.

Copy link
Member

@sarahdayan sarahdayan left a comment

Choose a reason for hiding this comment

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

I agree it's a more pragmatic approach, and we can make sure to handle empty class names in consuming libraries if we think it matters.

packages/shared/src/__tests__/cx.test.ts Outdated Show resolved Hide resolved
@Haroenv Haroenv enabled auto-merge (squash) October 17, 2022 09:24
@Haroenv Haroenv merged commit 2ec0751 into master Oct 17, 2022
@Haroenv Haroenv deleted the fix/cx-no-undefined branch October 17, 2022 09:25
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.

3 participants