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: improve type test #99

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

brunoti
Copy link

@brunoti brunoti commented Jun 10, 2024

I was making some BEM CSS transformers for Vite and stumbled on a bug:

The module.css will be transformed to something resembling this:

const ClassIdentifierMap = {}
ClassIdentifierMap['block'] = new String('block')
ClassIdentifierMap['block']['element'] = new String('block__element')
ClassIdentifierMap['block']['element']['$hasError'] = new String('block__element--has-error')

export default ClassIdentifierMap

Using it as:

import classes from './Whatever.module.css'

clsx(classes.block.element, hasError && classes.block.element.$hasError)

It will always fail because it will check and fail to see that all those are strings, treat it as an object, and try to check the keys.

This PR fixes it on both clsx and clsx/lite.

@brunoti brunoti marked this pull request as draft June 10, 2024 15:25
@brunoti
Copy link
Author

brunoti commented Jun 10, 2024

Converted to draft to add tests

@brunoti brunoti marked this pull request as ready for review June 10, 2024 15:48
@brunoti
Copy link
Author

brunoti commented Jun 10, 2024

Tests added!

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.

1 participant