nextui-org / tailwind-variants

🦄 Tailwindcss first-class variant API
https://tailwind-variants.org
MIT License
2.42k stars 68 forks source link

fix(tsconfig): add exactOptionalPropertyTypes #97

Closed douglasduteil closed 1 year ago

douglasduteil commented 1 year ago

Description

Additional context


What is the purpose of this pull request?

Before submitting the PR, please make sure you do the following

mskelton commented 1 year ago

Why?

douglasduteil commented 1 year ago

I experimented some issues with tailwind-variants and this compiler options. I'm wandering if the same errors hit the tailwind-variants tests.

Some like :


import { tv, type VariantProps } from "tailwind-variants";

const button = tv({
  variants: {
    intent: {
      primary: "bg-primary"
    }
  }
})

function DatButton({ intent }:  VariantProps<typeof button>) {
  return <button className={button({ intent })} />
}

Result with :

Type error: Argument of type '{ intent: "primary" | undefined;  }' is not assignable to parameter of type '({ intent?: "primary" } & ClassProp<...>) | undefined'.
  Type '{ intent: "primary" | undefined;  }' is not assignable to type '{ intent?: "primary" } & { ...; }' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
    Type '{ intent: "primary" | undefined;  }' is not assignable to type '{ intent?: "primary" }' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
      Types of property 'intent' are incompatible.
        Type '"primary" | undefined' is not assignable to type '"primary"'.
          Type 'undefined' is not assignable to type '"primary"'.
mskelton commented 1 year ago

@douglasduteil Thanks for the example. I updated the type decls to support exactOptionalPropertyTypes

douglasduteil commented 1 year ago

🎉 Thanks @mskelton