Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

svelte-check error when using ComponentType<Icon> #2114

Open
6 of 30 tasks
garrettpauls opened this issue May 1, 2024 · 6 comments · Fixed by #2119
Open
6 of 30 tasks

svelte-check error when using ComponentType<Icon> #2114

garrettpauls opened this issue May 1, 2024 · 6 comments · Fixed by #2119
Labels
🐛 bug Something isn't working

Comments

@garrettpauls
Copy link

Package

  • lucide
  • lucide-angular
  • lucide-flutter
  • lucide-preact
  • lucide-react
  • lucide-react-native
  • lucide-solid
  • lucide-svelte
  • lucide-vue
  • lucide-vue-next
  • Figma plugin
  • source/main
  • other/not relevant

Version

0.376.0

Can you reproduce this in the latest version?

  • Yes
  • No

Browser

  • Chrome/Chromium
  • Firefox
  • Safari
  • Edge
  • iOS Safari
  • Opera
  • Other/not relevant

Operating system

  • Windows
  • Linux
  • macOS
  • ChromeOS
  • iOS
  • Android
  • Other/not relevant

Description

When using the latest version of lucide-svelte (0.376.0 and 0.376.1), using the pattern described on the Lucide website to pass icon components causes the following error in svelte-check:

Error: Type 'typeof Home' is not assignable to type 'ComponentType<Icon>'.
  Types of construct signatures are incompatible.
    Type 'new (options: ComponentConstructorOptions<IconProps>) => Home' is not assignable to type 'new (options: ComponentConstructorOptions<{ [x: string]: any; name?: string | undefined; color?: string | undefined; size?: string | number | undefined; strokeWidth?: string | number | undefined; absoluteStrokeWidth?: boolean | undefined; iconNode: IconNode; mergeClasses?: (<ClassType = string>(...classes: ClassType[]) => string) | undefined; }>) => Icon'.
      Property 'mergeClasses' is missing in type 'SvelteComponentTyped<IconProps, { [evt: string]: CustomEvent<any>; }, { default: {}; }>' but required in type 'Icon'. (ts)
                        href: '/',
                        icon: Home,
                },

Steps to reproduce

Follow the steps documented on the Lucide website to create a new project using the Svelte library, then copy the typescript example from the Types section and run svelte-check.

  1. Create a new Svelte project using Typescript:
    npm create svelte@latest myapp
    cd myapp
    npm install
    npm run dev
    
  2. Install lucide-svelte: npm install lucide-svelte
  3. Open the default +page.svelte file and replace its contents with the example contents from the Types section on the Lucide website:
    <script lang="ts">
      import Home from 'lucide-svelte/icons/home';
      import Library from 'lucide-svelte/icons/library';
      import Cog from 'lucide-svelte/icons/cog';
      import type { ComponentType } from 'svelte';
      import type { Icon } from 'lucide-svelte';
    
      type MenuItem = {
        name: string;
        href: string;
        icon: ComponentType<Icon>;
      }
    
      const menuItems: MenuItem[] = [
        {
          name: 'Home',
          href: '/',
          icon: Home,
        },
        {
          name: 'Blog',
          href: '/blog',
          icon: Library,
        },
        {
          name: 'Projects',
          href: '/projects',
          icon: Cog,
        }
      ];
    </script>
    
    {#each menuItems as item}
      <a href={item.href}>
       <svelte:component this={item.icon} />
        <span>{item.name}</span>
      </a>
    {/each}
    
  4. Run svelte-check against the project: npm run check
  5. It should pass, but instead causes the following errors:
    npm run check
    
    > lucide-typescript-bug@0.0.1 check
    > svelte-kit sync && svelte-check --tsconfig ./tsconfig.json
    
    
    ====================================
    Loading svelte-check in workspace: s:\code\lucide-typescript-bug
    Getting Svelte diagnostics...
    
    s:\code\lucide-typescript-bug\src\routes\+page.svelte:18:4
    Error: Type 'typeof Home' is not assignable to type 'ComponentType<Icon>'.
      Types of construct signatures are incompatible.
        Type 'new (options: ComponentConstructorOptions<IconProps>) => Home' is not assignable to type 'new (options: ComponentConstructorOptions<{ [x: string]: any; name?: string | undefined; color?: string | undefined; size?: string | number | undefined; strokeWidth?: string | number | undefined; absoluteStrokeWidth?: boolean | undefined; iconNode: IconNode; mergeClasses?: (<ClassType = string>(...classes: ClassType[]) => string) | undefined; }>) => Icon'.
          Property 'mergeClasses' is missing in type 'SvelteComponentTyped<IconProps, { [evt: string]: CustomEvent<any>; }, { default: {}; }>' but required in type 'Icon'. (ts)
                            href: '/',
                            icon: Home,
                    },
    
    
    s:\code\lucide-typescript-bug\src\routes\+page.svelte:23:4
    Error: Type 'typeof Library' is not assignable to type 'ComponentType<Icon>'.
      Types of construct signatures are incompatible.
        Type 'new (options: ComponentConstructorOptions<IconProps>) => Library' is not assignable to type 'new (options: ComponentConstructorOptions<{ [x: string]: any; name?: string | undefined; color?: string | undefined; size?: string | number | undefined; strokeWidth?: string | number | undefined; absoluteStrokeWidth?: boolean | undefined; iconNode: IconNode; mergeClasses?: (<ClassType = string>(...classes: ClassType[]) => string) | undefined; }>) => Icon'.
          Property 'mergeClasses' is missing in type 'SvelteComponentTyped<IconProps, { [evt: string]: CustomEvent<any>; }, { default: {}; }>' but required in type 'Icon'. (ts)
                            href: '/blog',
                            icon: Library,
                    },
    
    
    s:\code\lucide-typescript-bug\src\routes\+page.svelte:28:4
    Error: Type 'typeof Cog' is not assignable to type 'ComponentType<Icon>'.
      Types of construct signatures are incompatible.
        Type 'new (options: ComponentConstructorOptions<IconProps>) => Cog' is not assignable to type 'new (options: ComponentConstructorOptions<{ [x: string]: any; name?: string | undefined; color?: string | undefined; size?: string | number | undefined; strokeWidth?: string | number | undefined; absoluteStrokeWidth?: boolean | undefined; iconNode: IconNode; mergeClasses?: (<ClassType = string>(...classes: ClassType[]) => string) | undefined; }>) => Icon'.
          Property 'mergeClasses' is missing in type 'SvelteComponentTyped<IconProps, { [evt: string]: CustomEvent<any>; }, { default: {}; }>' but required in type 'Icon'. (ts)
                            href: '/projects',
                            icon: Cog,
                    }
    
    
    s:\code\lucide-typescript-bug\src\routes\+page.svelte:35:4
    Error: Property 'iconNode' is missing in type '{}' but required in type '{ [x: string]: any; name?: string | undefined; color?: string | undefined; size?: string | number | undefined; strokeWidth?: string | number | undefined; absoluteStrokeWidth?: boolean | undefined; iconNode: IconNode; mergeClasses?: (<ClassType = string>(...classes: ClassType[]) => string) | undefined; }'. (ts)
            <a href={item.href}>
                    <svelte:component this={item.icon} />
                    <span>{item.name}</span>
    
    
    ====================================
    svelte-check found 4 errors and 0 warnings in 1 file
    

Checklist

  • I have searched if someone has submitted a similar issue before and there weren't any. (Please make sure to also search closed issues, as this issue might already have been resolved.)
@garrettpauls garrettpauls added the 🐛 bug Something isn't working label May 1, 2024
@Wizzel1
Copy link

Wizzel1 commented May 2, 2024

Same here at ^0.377.0

@ngowuys
Copy link

ngowuys commented May 20, 2024

I'm facing with same problem, hope there will be a PR to fix this soon.

@jprinaldi
Copy link

I'm still experiencing this issue with version 0.379.0. Can somebody else confirm?

@gafagarion
Copy link

I'm still having the issue with 0.379.0 as well

@garrettpauls
Copy link
Author

I can confirm this still happens in 0.379.0 as well. The error message from svelte-check is now different, however:

Error: Type 'typeof Home' is not assignable to type 'ComponentType<Icon>'.
  Types of construct signatures are incompatible.
    Type 'new (options: ComponentConstructorOptions<IconProps>) => Home' is not assignable to type 'new (options: ComponentConstructorOptions<{ [x: string]: any; name?: string | undefined; color?: string | undefined; size?: string | number | undefined; strokeWidth?: string | number | undefined; absoluteStrokeWidth?: boolean | undefined; iconNode: IconNode; }>) => Icon'.
      Construct signature return types 'Home' and 'Icon' are incompatible.
        The types of '$$prop_def' are incompatible between these types.
          Type 'IconProps' is not assignable to type '{ [x: string]: any; name?: string | undefined; color?: string | undefined; size?: string | number | undefined; strokeWidth?: string | number | undefined; absoluteStrokeWidth?: boolean | undefined; iconNode: IconNode; }'. (ts)
                        href: '/',
                        icon: Home,
                },

The full output from my original test project (updated to 0.379.0) is as follows:

npm run check

> lucide-typescript-bug@0.0.1 check
> svelte-kit sync && svelte-check --tsconfig ./tsconfig.json


====================================
Loading svelte-check in workspace: s:\code\lucide-typescript-bug
Getting Svelte diagnostics...

s:\code\lucide-typescript-bug\src\routes\+page.svelte:18:4
Error: Type 'typeof Home' is not assignable to type 'ComponentType<Icon>'.
  Types of construct signatures are incompatible.
    Type 'new (options: ComponentConstructorOptions<IconProps>) => Home' is not assignable to type 'new (options: ComponentConstructorOptions<{ [x: string]: any; name?: string | undefined; color?: string | undefined; size?: string | number | undefined; strokeWidth?: string | number | undefined; absoluteStrokeWidth?: boolean | undefined; iconNode: IconNode; }>) => Icon'.
      Construct signature return types 'Home' and 'Icon' are incompatible.
        The types of '$$prop_def' are incompatible between these types.
          Type 'IconProps' is not assignable to type '{ [x: string]: any; name?: string | undefined; color?: string | undefined; size?: string | number | undefined; strokeWidth?: string | number | undefined; absoluteStrokeWidth?: boolean | undefined; iconNode: IconNode; }'. (ts)
                        href: '/',
                        icon: Home,
                },


s:\code\lucide-typescript-bug\src\routes\+page.svelte:23:4
Error: Type 'typeof Library' is not assignable to type 'ComponentType<Icon>'.
  Types of construct signatures are incompatible.
    Type 'new (options: ComponentConstructorOptions<IconProps>) => Library' is not assignable to type 'new (options: ComponentConstructorOptions<{ [x: string]: any; name?: string | undefined; color?: string | undefined; size?: string | number | undefined; strokeWidth?: string | number | undefined; absoluteStrokeWidth?: boolean | undefined; iconNode: IconNode; }>) => Icon'.
      Construct signature return types 'Library' and 'Icon' are incompatible.
        The types of '$$prop_def' are incompatible between these types.
          Type 'IconProps' is not assignable to type '{ [x: string]: any; name?: string | undefined; color?: string | undefined; size?: string | number | undefined; strokeWidth?: string | number | undefined; absoluteStrokeWidth?: boolean | undefined; iconNode: IconNode; }'. (ts)
                        href: '/blog',
                        icon: Library,
                },


s:\code\lucide-typescript-bug\src\routes\+page.svelte:28:4
Error: Type 'typeof Cog' is not assignable to type 'ComponentType<Icon>'.
  Types of construct signatures are incompatible.
    Type 'new (options: ComponentConstructorOptions<IconProps>) => Cog' is not assignable to type 'new (options: ComponentConstructorOptions<{ [x: string]: any; name?: string | undefined; color?: string | undefined; size?: string | number | undefined; strokeWidth?: string | number | undefined; absoluteStrokeWidth?: boolean | undefined; iconNode: IconNode; }>) => Icon'.
      Construct signature return types 'Cog' and 'Icon' are incompatible.
        The types of '$$prop_def' are incompatible between these types.
          Type 'IconProps' is not assignable to type '{ [x: string]: any; name?: string | undefined; color?: string | undefined; size?: string | number | undefined; strokeWidth?: string | number | undefined; absoluteStrokeWidth?: boolean | undefined; iconNode: IconNode; }'. (ts)
                        href: '/projects',
                        icon: Cog,
                }


s:\code\lucide-typescript-bug\src\routes\+page.svelte:35:4
Error: Property 'iconNode' is missing in type '{}' but required in type '{ [x: string]: any; name?: string | undefined; color?: string | undefined; size?: string | number | undefined; strokeWidth?: string | number | undefined; absoluteStrokeWidth?: boolean | undefined; iconNode: IconNode; }'. (ts)
        <a href={item.href}>
                <svelte:component this={item.icon} />
                <span>{item.name}</span>


====================================
svelte-check found 4 errors and 0 warnings in 1 file

@jguddas jguddas reopened this May 21, 2024
@dadebue
Copy link

dadebue commented May 24, 2024

Happening for me as well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants