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

[Bug] Type error typeof Meta when used with Svelte 3 #121

Closed
mcmxcdev opened this issue Aug 11, 2023 · 5 comments
Closed

[Bug] Type error typeof Meta when used with Svelte 3 #121

mcmxcdev opened this issue Aug 11, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@mcmxcdev
Copy link

Describe the bug

I am encountering TS issues with all imports from @storybook/addon-svelte-csf:

Argument of type 'typeof Meta' is not assignable to parameter of type 'ConstructorOfATypedSvelteComponent'.
  Type 'typeof Meta' provides no match for the signature 'new (args: { target: any; props?: any; }): ATypedSvelteComponent'.

Possible causes:
- You use the instance type of a component where you should use the constructor type
- Type definitions are missing for this Svelte Component. If you are using Svelte 3.31+, use SvelteComponentTyped to add a definition:
  import type { SvelteComponentTyped } from "svelte";
  class ComponentName extends SvelteComponentTyped<{propertyName: string;}> {}

The exact same message with a different typeof is repeated for Template and Story imports.

Expected behavior

No TS issues

Environment

  • OS: Ubuntu 23.04
  • Node.js version: v18.17.1
  • NPM version: pnpm 8.6.10
  • Browser (if applicable): Brave
  • Browser version (if applicable): Version 1.56.20 Chromium: 115.0.5790.171 (Official Build) (64-bit)
  • Device (if applicable): Desktop

Additional context

Story looks like this:

<script lang="ts">
  import { Meta, Template, Story } from '@storybook/addon-svelte-csf'
  import Space from '$lib/components/ui/Space.svelte'
</script>

<Meta title="Actions/Space" component={Space} />

<Template let:args>
  <Space {...args} />
</Template>

<Story name="Horizontal" />

<Story name="Vertical" />

Config is as follows:

import type { StorybookConfig } from '@storybook/sveltekit'

const config: StorybookConfig = {
  stories: [
    {
      directory: '../src/stories/**',
      files: '*.stories.@(ts|svelte)',
      titlePrefix: 'Design System',
    },
  ],
  addons: [
    '@storybook/addon-interactions',
    '@storybook/addon-links',
    '@storybook/addon-a11y',
    '@storybook/addon-svelte-csf',
    {
      name: '@storybook/addon-essentials',
      options: {
        backgrounds: true,
      },
    },
    {
      name: '@storybook/addon-styling',
      options: {},
    },
  ],
  framework: {
    name: '@storybook/sveltekit',
    options: {},
  },
  docs: {
    autodocs: false,
  },
  core: { disableTelemetry: true },
}

export default config
@mcmxcdev mcmxcdev added the bug Something isn't working label Aug 11, 2023
@zhyuhan
Copy link

zhyuhan commented Aug 13, 2023

Are you using Svelte 3? I'm using Svelte 3 in my SvelteKit project and also encountered the same type errors.

This might be an issue with new types in Svelte 4. I created a new SvelteKit project with Svelte 4 and no errors showed up.

@mcmxcdev
Copy link
Author

I already feared that this would be the case, thanks for confirming it!

@mcmxcdev
Copy link
Author

Fixed by upgrading to Svelte 4.

This dependency needs to drop Svelte 3 from it's peer dependencies here since it's misleading: https://github.com/storybookjs/addon-svelte-csf/blob/main/package.json#L98

@JReinhold JReinhold changed the title [Bug] Strange TS issues for imports coming from @storybook/addon-svelte-csf [Bug] Type error typeof Meta when used with Svelte 3 Aug 21, 2023
@JReinhold
Copy link
Collaborator

JReinhold commented Aug 21, 2023

@RSWilli seems like Svelte 4 did break our typing system after all - I'm not sure there's an easy fix here.

My suggestion would be to release a new major which only allows Svelte 4 as a peer dependency.
Alongside that we could also release a new patch that that only allows Svelte 3 as a peer dependency, so we'd release two new versions that clearly defines the necessary dependencies.
Thoughts?

@benmccann
Copy link
Contributor

I believe this is fixed now. Please use version 3.0.10 of this plugin with Svelte 3 and version 4 of this plugin with Svelte 4

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

No branches or pull requests

4 participants