Storybook: addon-actions doesn't have a TS declaration file

Created on 30 May 2017  路  12Comments  路  Source: storybookjs/storybook

Which means trying to import { action } will result in:

(3,24): error TS7016: Could not find a declaration file for module '@storybook/addon-actions'. '/home/vincent/Code/moody/frontend/node_modules/@storybook/addon-actions/dist/index.js' implicitly has an 'any' type.
actions bug

Most helpful comment

PS - as a temporary workaround you can add a type definition to your project, which I did successfully in @leonidax 's project:

declare module "@storybook/addon-actions" {
  export function action(name: string, ...params: any[]): any;
}

All 12 comments

Yes I have the same issue, I also tried to do something similar because the Readme.md in "@storybook/addon-actions" points you to do the following:

import { action, decorateAction } from "@storybook/addon-actions"

But there is no *.d.ts file

Which also makes me wonder which is the right way to use actions

Since you can also import it directly from "@storybook/react"

I tried like this but like the ticket #1153 the actions are not being logged.

@Keats @leonidax created an umbrella issue here: https://github.com/storybooks/storybook/issues/1166

Would love your feedback on the issue. And, if you're up for it, help to make this happen!

(not sure if we are considering lack of TS support a bug or not at this point)

@tmeasday seems like enough people are using it that it's close enough 馃槃

@shilman Sure, I would be happy to help... do you have a IRC channel or how can I join your slack channel?

@tmeasday I would say that more and more people are going to start using TypeScript

https://trends.google.com/trends/explore?date=all&q=TypeScript

@leonidax slack is here. we are excited and grateful for your help! 馃帀

https://storybooks-slackin.herokuapp.com/

I created an example project with storybook typescript and less

https://github.com/leonidax/storybook-ts-less-example

Thanks for creating a repo @leonidax . I checked it out and answered your question on #1153

As for the lack of typescript definitions on the actions package, here's the story:

  • actions/linkTo used to come bundled with @kadira/storybook. they still come bundled with @storybook/react but are now deprecated and we plan to remove them soon. this is documented (here)[https://github.com/storybooks/storybook/blob/master/MIGRATION.md#deprecated-embedded-addons]
  • when i deprecated the packages, i didn't update the typescript definitions so they are still declared in @storybook/react but are not declared in in the @storybook/addon-actions package. they should be.
  • the problem you had with actions not getting logged was due to a bug in your code. AFAICT it was a different problem from the other problems people were having with inconsistent NPM modules.

And for the followup, I think we should have a uniform way to support Typescript in Storybook packages so that all @storybook/* have proper type definitions.

I'd like to close this issue and continue the discussion in #1166. @leonidax @Keats are you OK with that?

PS - as a temporary workaround you can add a type definition to your project, which I did successfully in @leonidax 's project:

declare module "@storybook/addon-actions" {
  export function action(name: string, ...params: any[]): any;
}

Yes I did something like that directly in the module but I suppose I can put it in a global.d.ts while the proper fix gets it to a released version.

Im ok with closing this ticket and moving the conversation to #1166

Thanks for all the help :)

Thanks @leonidax ! Would have no idea what's going on without your sample repo. Super helpful!! 馃弲馃弳 馃憦

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dnlsandiego picture dnlsandiego  路  3Comments

levithomason picture levithomason  路  3Comments

purplecones picture purplecones  路  3Comments

tlrobinson picture tlrobinson  路  3Comments

shilman picture shilman  路  3Comments