joe-bell / cva

Class Variance Authority
https://cva.style
Apache License 2.0
5.46k stars 107 forks source link

TW Intellisense doesn't work when trying to use `cva` with generic params #285

Closed kapobajza closed 2 months ago

kapobajza commented 2 months ago

Hello.

Describe the bug Intellisense doesn't work when trying to use cva with generic type params.

To Reproduce Steps to reproduce the behavior:

  1. Follow the steps to enable autocompletion in the docs
  2. Try using cva with generic type params:
type InputVariant = "primary" | "secondary";

type InputVariantConfig = {
  variant: Record<InputVariant, string>;
};

const inputVariants = cva<InputVariantConfig>(
  "border-input bg-background", // Intellisense doesn't work here
  {
    variants: {
      variant: {
        primary: "bg-primary", // Intellisense doesn't work here
        secondary: "bg-secondary" // Intellisense doesn't work here
      }
    }
  }
)

If I remove the <InputVariantConfig> generic type param, it works as expected.

Expected behavior Intellisense should be working even when adding generic type params

Desktop (please complete the following information):

Additional context I found a solution for this and I'll create a PR to address it.

joe-bell commented 2 months ago

Hey! Thanks, but cva isn't designed to accept generic parameters. cva@1.0 will make this clearer