Describe the bug
I've just upgraded from Storybook 5.0.6 to 5.2.6. To get anything to work with TypeScript I've removed all the Definitely Typed definitions and just rely on the built-in typings. Unfortunately @storybook/addon-storyshots doesn't seem to have built-in typings yet, and if I include "@types/storybook__addon-storyshots": "^3.4.8" in the project (the latest available) it breaks the rest of Storybook for TS.
It looks like Storybook 5.3 will have typings for Storyshots. The workaround is to temporarily add your own typings file locally as @types/storybook__addon-storyshots/index.d.ts, e.g.:
declare module "@storybook/addon-storyshots" {
export default function initStoryshots<Rendered>(options: InitOptions<Rendered>): void;
export interface InitOptions<Rendered = any> {
configPath?: string;
suite?: string;
storyKindRegex?: RegExp;
storyNameRegex?: RegExp;
framework?: string;
renderer?: (node: React.ReactElement<any>) => Rendered;
serializer?: (rendered: Rendered) => any;
integrityOptions?: {};
}
}
To Reproduce
Steps to reproduce the behavior:
import initStoryshots from "@storybook/addon-storyshots"; in TSExpected behavior
Typings should be available, either as a built-in or through Definitely Typed.
System:
Environment Info:
System:
OS: macOS 10.15
CPU: (12) x64 Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
Binaries:
Node: 12.13.0 - /usr/local/bin/node
npm: 6.12.0 - /usr/local/bin/npm
Browsers:
Chrome: 78.0.3904.97
Firefox: 70.0
Safari: 13.0.2
Can you add the error you get when storybook won't start, please?
In the latest beta the types should be there, would you mind testing that for us?
As Kai asked, an exact error would help us trace what's happening and possibly how to patch/fix.
This is the error I get when compiling our TS application with "@types/storybook__addon-storyshots": "5.1.1":
@xxx/core: ../../node_modules/@types/storybook__addon-storyshots/index.d.ts(9,10): error TS2305: Module '"../../../../../../../../Users/stevebaxter/Code/xxx/yyy/node_modules/@storybook/react/dist/client"' has no exported member 'StoryObject'.
@xxx/core: npm ERR! code ELIFECYCLE
@xxx/core: npm ERR! errno 2
@xxx/core: npm ERR! @xxx/[email protected] build:ts: `tsc`
@xxx/core: npm ERR! Exit status 2
@xxx/core: npm ERR!
@xxx/core: npm ERR! Failed at the @xxx/[email protected] build:ts script.
@xxx/core: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
@xxx/core: npm ERR! A complete log of this run can be found in:
@xxx/core: npm ERR! /Users/stevebaxter/.npm/_logs/2019-11-21T20_55_35_581Z-debug.log
Here are all the versions:
"@storybook/addon-actions": "5.2.6",
"@storybook/addon-console": "1.2.1",
"@storybook/addon-info": "5.2.6",
"@storybook/addon-knobs": "5.2.6",
"@storybook/addon-links": "5.2.6",
"@storybook/addon-storyshots": "5.2.6",
"@storybook/react": "5.2.6",
"@types/storybook__addon-storyshots": "5.1.1"
Happy to give the beta a quick whirl, can I get it through npm?
Ah, found the beta. With beta.3 the typings all seem fine and it all compiles and works for me.
@types/storybook__addon-storyshots are still relying on types that were defined in @types/storybook__react that explains why StoryObject is not found.
We are still working on deleting outdated types and fixing required ones in https://github.com/DefinitelyTyped/DefinitelyTyped/pull/40475
As soon as 5.3.0 will be out we will be able to also delete @types/storybook__addon-storyshots and everything should be ok (as when you tried with beta.3).
Cool, will look forward to 5.3! This is easy to work around by creating a local type definitions file with the information above, hopefully that will help anyone who hits the same problem. My vote would be to close this as it is fixed in 5.3.
Most helpful comment
Ah, found the beta. With beta.3 the typings all seem fine and it all compiles and works for me.