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

[addon-viewport] TypeScript types missing #8611

Closed
screendriver opened this issue Oct 29, 2019 · 6 comments
Closed

[addon-viewport] TypeScript types missing #8611

screendriver opened this issue Oct 29, 2019 · 6 comments

Comments

@screendriver
Copy link

Describe the bug

The TypeScript types in @storybook/addon-viewport are not working because you are missing the types field in your package.json is missing like it is in knobs package.json. So when you try something like import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport'; you get

Could not find a declaration file for module '@storybook/addon-viewport'. '/Users/me/project/node_modules/@storybook/addon-viewport/preview.js' implicitly has an 'any' type.

I tried to open a pull request but I was unsure because there is no index.ts in addons/viewport/src/ and the types property should point to one.

What I am doing in my project is import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport'; so that would mean to re-export everything from the index.ts file.

To Reproduce

Use TypeScript in your project and try to import import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport';

Expected behavior

Should compile

Screenshots

Code snippets

System:

Additional context

@shilman
Copy link
Member

shilman commented Oct 29, 2019

@screendriver mind issuing a small PR for this?

@shilman shilman added the bug label Oct 29, 2019
@screendriver
Copy link
Author

As I already wrote I tried to open a pull request but had some serious thoughts about it. Should I just re-export everything from a non-existent index.ts?

@shilman
Copy link
Member

shilman commented Oct 30, 2019

@kroeder @gaetanmaisse @ndelangen can you advise?

@gaetanmaisse
Copy link
Member

I think a good option is to move preview.js in addons/viewport/src/, migrate it to TS and finally update both main and types in package.json to point to the new files, something like:

"main": "dist/preview.js",
"types": "dist/preview.d.ts",

This should not create breaking change and should also export TS types correctly :)
Are you ok with this solution @kroeder @ndelangen?

@shilman
Copy link
Member

shilman commented Nov 16, 2019

Whoopee!! I just released https://github.com/storybookjs/storybook/releases/tag/v5.3.0-alpha.47 containing PR #8848 that references this issue. Upgrade today to try it out!

You can find this prerelease on the @next NPM tag.

Closing this issue. Please re-open if you think there's still more to do.

@shilman shilman closed this as completed Nov 16, 2019
@shilman
Copy link
Member

shilman commented Nov 30, 2019

ZOMG!! I just released https://github.com/storybookjs/storybook/releases/tag/v5.2.7 containing PR #8848 that references this issue. Upgrade today to try it out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants