flekschas / svelte-simple-modal

A simple, small, and content-agnostic modal for Svelte v3 and v4
https://svelte.dev/repl/b95ce66b0ef34064a34afc5c0249f313
MIT License
422 stars 30 forks source link

Argument of type 'typeof Popup__SvelteComponent_' is not assignable to parameter of type 'typeof SvelteComponent'. #102

Closed KoljaL closed 1 year ago

KoljaL commented 1 year ago

Fist: It works and it works great :-)

But i get an type-error on Popupin the last line:

import { writable } from 'svelte/store';
import Modal, { bind } from 'svelte-simple-modal';
import Popup from '$lib/components/Popup.svelte';
const modal: any = writable(false);
const showSources = (): void => modal.set(bind(Popup, {}));

This is the full error message from VSCode:

Argument of type 'typeof Popup__SvelteComponent_' is not assignable to parameter of type 'typeof SvelteComponent'.
  Types of construct signatures are incompatible.
    Type 'new (options: ComponentConstructorOptions<{ message?: string | undefined; }>) => Popup__SvelteComponent_' is not assignable to type 'new <Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any>(options: ComponentConstructorOptions<Props>) => SvelteComponent<...>'.
      Construct signature return types 'Popup__SvelteComponent_' and 'SvelteComponent<Props, Events, Slots>' are incompatible.
        The types of '$$prop_def' are incompatible between these types.
          Type '{ message?: string | undefined; }' is not assignable to type 'Props'.
            '{ message?: string | undefined; }' is assignable to the constraint of type 'Props', but 'Props' could be instantiated with a different subtype of constraint 'Record<string, any>'.

How do I set the correct Types?

flekschas commented 1 year ago

Sorry about that! Not sure what's going on. I haven't seen that error before. Which version of svelte-simple-modal and svelte have you installed?

alankrantas commented 1 year ago

This happened to me too when I tried to upgrade my Svelte 3 site to Svelte 4. The component type is changed hence the error. https://svelte.dev/docs/v4-migration-guide#sveltecomponenttyped-is-deprecated

Not a bug for Svelte 3 though.

KoljaL commented 1 year ago

Yes, I use #4 too.

flekschas commented 1 year ago

FYI, I have a PR #101 for adding support for Svelte v4. I just need to figure out another type issue that seems to be new since v4