clsx icon indicating copy to clipboard operation
clsx copied to clipboard

fix: improve type test

Open brunoti opened this issue 1 year ago • 2 comments

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 avatar Jun 10 '24 15:06 brunoti