Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Typescript compatibility #144

Closed
mdcorriveau opened this issue Mar 31, 2017 · 5 comments
Closed

Typescript compatibility #144

mdcorriveau opened this issue Mar 31, 2017 · 5 comments

Comments

@mdcorriveau
Copy link

Hi,

I'm currently converting my react application and storybook to typescript. I currently have a bunch of error with the addWithInfo which return this error :
TS2339:Property 'addWithInfo' does not exist on type 'Story'.

While react-storybook is already providing a storybook.d.ts file in their package, do you think it'll be a great idea to do the same with react-storybook-addon-info ?

Thanks

@ndelangen
Copy link
Contributor

ndelangen commented Mar 31, 2017

Hey @mdcorriveau, thank you for reporting! Sounds you know a thing or 2 about typescript, would you be able to help us out by creating a PR?

@thani-sh thani-sh self-assigned this Apr 1, 2017
@thani-sh
Copy link
Contributor

thani-sh commented Apr 1, 2017

I've never done this before but perhaps we can add a type definition file to this repo which will add the method to the story type. I found this page in typescript documentation about merging type declarations. I'll check it out and comment here.

@mdcorriveau
Copy link
Author

I'll take some time to check this out too this monday the 3rd, i'll get back at you if I've found something !

@mdcorriveau
Copy link
Author

mdcorriveau commented Apr 3, 2017

storybookjs/storybook#33
storybookjs/storybook#700

Here's what the ts configuration of the original storybook module looks like :

declare var module: any; // dangerous

interface StoryDecorator {
(story: Function, context: { kind: string, story: string }): Object;
}

interface Story {
add (storyName: string, callback: Function): Story;
addDecorator (decorator: StoryDecorator): Story;
}

export function addDecorator(decorator: StoryDecorator): void;
export function linkTo(name: string, ...params: any[]): void;
export function storiesOf(name: string, module: any): Story;
export function action(name: string, ...params: any[]): any;

They also have this line in the package.json :

"typings": "./config/storybook.d.ts",

@kudresov
Copy link

It would be good to fix this issue. As a temp workaround you could cast storiesOf to make TS happy like so: (storiesOf('Story Name', module) as any).addWithInfo(..

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

4 participants