storybookjs / addon-svelte-csf

[Incubation] CSF using Svelte components.
MIT License
103 stars 32 forks source link

[Bug] Types definitions are missing in 3.0.5 #116

Closed EugeneDraitsev closed 1 year ago

EugeneDraitsev commented 1 year ago

Describe the bug

Types definitions are missing in 3.0.5

Steps to reproduce the behavior

  1. Create a story with
    <script lang="ts">
    import { Meta, Story, Template } from '@storybook/addon-svelte-csf';
    </script>
  2. Run yarn make check or svelte-check or tsc --noEmit
  3. See an error:
    Error: Cannot find module '@storybook/addon-svelte-csf' or its corresponding type declarations. (ts)
    <script lang="ts">
    import { Meta, Story, Template } from '@storybook/addon-svelte-csf';

Expected behavior

No tsc error

Additional context

It works fine with @storybook/addon-svelte-csf version 3.0.4

Repo by @olafurw: olafurw/addon-svelte-csf-import-bug (originally #117)

hobbes7878 commented 1 year ago

Should be fixed in https://github.com/storybookjs/addon-svelte-csf/pull/115.

EugeneDraitsev commented 1 year ago

Hmm, it still fails with 3.0.6

hobbes7878 commented 1 year ago

OK, I think the issue is you'll need your moduleResolution set to node16 or nodenext in your tsconfig for TypeScript to properly pickup the exported types.

Can you try that @EugeneDraitsev / @olafurw?

olafurw commented 1 year ago

It works but moduleResolution is something that is set by Svelte in the .svelte-kit/tsconfig.json file to be "moduleResolution": "node" so this isn't a fix but a workaround I would say.

How can anyone install the addon-svelte-csf and start using it when they also have to add a configuration line to their tsconfig.json file?

hobbes7878 commented 1 year ago

I won't pretend to be an expert in these settings, but looking at the TS docs on moduleResolution, this might actually make a good argument that svelte-kit's tsconfig should be node16 or nodenext since their Node support range is ^16.14 || >=18.

Will check over there and see what's what.

hobbes7878 commented 1 year ago

OK, so turns out they've had this discussion over the fence and landed on: https://github.com/sveltejs/kit/issues/9007#issuecomment-1427635169

... which is sticking with node (now node10) until the new bundler setting comes in 5.0.

That's fine, but I hear @olafurw on the awkwardness of changing the typescript settings just for this package.

I think we could safely add back the main and types fields to package.json and then we're all living in happy harmony with both modern exports and classic options.

Gonna test that and make a PR.

JReinhold commented 1 year ago

Hope this is fixed now in 3.0.7, if not we'll reopen this issue.

Thanks for being very quick about this @hobbes7878, @EugeneDraitsev and @olafurw .

EugeneDraitsev commented 1 year ago

Thank you for the super quick fix!