storybookjs/addon-svelte-csf

[Bug] Types definitions are missing in 3.0.5

EugeneDraitsev opened this issue ยท 8 comments

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>
  1. Run yarn make check or svelte-check or tsc --noEmit
  2. 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)

Should be fixed in #115.

Hmm, it still fails with 3.0.6

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?

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?

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.

OK, so turns out they've had this discussion over the fence and landed on: sveltejs/kit#9007 (comment)

... 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.

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 .

Thank you for the super quick fix!