Skip to content

Typescript types for component selectors that use object syntax in emotion #99

@idrm

Description

@idrm

The existing demo of twin.macro + vite + emotion does not appear to allow component selectors using object syntax, e.g. as in the following snippet:

const Child = styled.div({
  color: 'red',
})

const Parent = styled.div({
  [Child]: {
    color: 'green',
  },
})

In order to enable that feature I had to add @emotion/babel-plugin as a dev dependency and inside the babel plugin list in vite.config.ts. While that made component selectors work, the type definitions provided in the vite+emotion example still flagged the [Child]:{...} selector as invalid. You can see the behavior in this CS. Can this be corrected by expanding the types in twin.d.ts, similar to the suggestion in ben-rogerson/twin.macro#116?

One other notable aspect of such an addition -- the component selector can be arbitrarily deep inside the selector tree, e.g. {'&:hover': { [Child]: { color: 'green' }}}.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions