saadeghi / daisyui

🌼 🌼 🌼 🌼 🌼  The most popular, free and open-source Tailwind CSS component library
https://daisyui.com
MIT License
34.25k stars 1.31k forks source link

bug: Wrong inferred type when importing daisyUI #2653

Open Stadly opened 11 months ago

Stadly commented 11 months ago

What version of daisyUI are you using?

v4.4.19

Which browsers are you seeing the problem on?

All browsers

Reproduction URL

https://stackblitz.com/edit/stackblitz-starters-upqwgb?file=tailwind.config.ts

Describe your issue

When importing daisyUI as an ES module its type is inferred as any instead of the correct type. Consider the following:

// tailwind.config.ts
import type { Config } from 'tailwindcss';
import * as forms from '@tailwindcss/forms';
import daisyui from 'daisyui';

export const configWithForms: Config = {
  content: [],
  theme: {
    extend: {},
  },
  plugins: [forms],
};

export const configWithDaisyUI: Config = {
  content: [],
  theme: {
    extend: {},
  },
  plugins: [daisyui],
};

npx eslint . gives the following error:

/home/projects/stackblitz-starters-upqwgb/tailwind.config.ts
  18:3  error  Unsafe assignment of type any[] to a variable of type (PluginCreator | { handler: PluginCreator; config?: Partial<Config>; } | { (options: any): { handler: PluginCreator; config?: Partial<...>; }; __isOptionsFunction: true; } | undefined)[]  @typescript-eslint/no-unsafe-assignment

There is no error on line 10, so the type of forms is inferred correctly, while the type of daisyui is inferred as any. I included @tailwindcss/forms just to show that it is possible for the type to be inferred correctly, and hopefully looking at that package can help with solving the issue.

By the way, the inferred type is also wrong when using the require syntax. require always returns type any, so both require("@tailwindcss/forms") and require("daisyui") are inferred as any.

Reproduction:

  1. Go to https://stackblitz.com/edit/stackblitz-starters-upqwgb?file=tailwind.config.ts
  2. Run npx eslint . in the terminal
github-actions[bot] commented 11 months ago

Thank you @Stadly for reporting issues. It helps daisyUI a lot 💚
I'll be working on issues one by one. I will help with this one as soon as a I find a solution.
In the meantime providing more details and reproduction links would be helpful.

damianobarbati commented 1 month ago

@Stadly did you solve this? I have the same issue.

Stadly commented 1 month ago

@Stadly did you solve this? I have the same issue.

Try setting "esModuleInterop": true in tsconfig.json. Got no idea why, but I think that's what solved it for me.

Stadly commented 1 month ago

Let's close this issue if you can confirm that it works :)