Skip to content

Limit inference of the variant object in recipes (cva, sva) #3363

Description

@islami00

Description

The cva, sva recipe functions currently infer both variants and the css of each variant. I would like them to only infer variant names and their values because the inferred css can be quite large.

Problem Statement/Justification

I propose this because of the following issues I've noticed when using cva/sva:

  1. In a library with the declaration setting on, I run into the typescript error: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.ts(7056) when trying to reuse styles across multiple variants in a recipe (example).
  2. Type errors in the variants object are not reported where they occur, rather at the variants property. This makes it hard to debug large recipes (example).
  3. It's possible to specify incorrect/nonexistent properties in the variants object (example).

Proposed Solution or API

I would like to suggest looser inference in the inferred variant type in cva and sva as shown in the following files:

  1. cva. The main change for cva is at this line
  2. sva. The main change for sva is at this line.

I'm not sure if these types are performant, but I hope this creates a starting point for limiting inference there.

Alternatives

For the max serialisation length error, I have tried using satisfies instead of directly setting the type of the shared styles to SystemStyleObject, but that seems a bit unintuitive.

i.e:

const shared = {} satisfies SystemStyleObject;
// instead of
const shared: SystemStyleObject = {}

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions