lukeed/clsxPublic

A tiny (239B) utility for constructing `className` strings conditionally.

TypeScript Issue

YO

``` "typescript": "5.0.4", "clsx": "1.2.1" ```

Hey there, I need clarification on what is happening right now. I have the following piece of code:

```ts import clsx from 'clsx'; import Link from 'next/link';

type ConnectWithUsButtonProps = { className?: string }; // This one fails as well. // type ConnectWithUsButtonProps = { className: string | undefined };

export function ConnectWithUsButton(props: ConnectWithUsButtonProps) { return ( <Link href="/" className={clsx( 'flex-shrink-0 bg-yellow-300 hover:bg-yellow-400 font-bold text-black rounded-full py-4 px-6 shadow-lg', // TODO: remove ! from className props.className! )} > Connect with us </Link> ); } ```

I am getting the following issue:

> Argument type string | undefined is not assignable to parameter type ClassValue

![Screen Shot 2023-05-16 at 11 47 02 PM](https://github.com/lukeed/clsx/assets/4237280/8f4601c0-d4cf-47c5-b8bb-a5d9b8b94cd3)

I am not sure why I must use `!` now when it used to work just fine before.

I do not get why this is happening. Everything seems just fine.

I really appreciate any help you can provide.

  1. CH

    @yordis yep you're right you don't need the non-null assertion ! as props.className has type `string | undefined` which falls within that of `type ClassValue = ClassArray | ClassDictionary | string | number | null | boolean | undefined`

    Try restarting your ts server?

  2. yordismentioned3 years ago on GitHub

  3. yordissubscribed3 years ago on GitHub

  4. YO
    Author

    I am going to assume it was LSP or whatever Intellij was doing ... odd

  5. yordisclosed3 years ago on GitHub