11import { defaultDecorateStory , combineParameters , addons , applyHooks , HooksContext , mockChannel } from '@storybook/preview-api' ;
22import type { ReactRenderer , Args } from '@storybook/react' ;
3- import type { ComponentAnnotations , StoryContext } from '@storybook/types' ;
3+ import type { ComponentAnnotations , Store_CSFExports , StoryContext } from '@storybook/types' ;
44import { isExportStory } from '@storybook/csf' ;
55
66export { StoriesWithPartialProps } from './types' ;
7- import type { GlobalConfig , StoriesWithPartialProps , StoryFile , TestingStory , TestingStoryPlayContext } from './types' ;
7+ import type { GlobalConfig , StoriesWithPartialProps , TestingStory , TestingStoryPlayContext } from './types' ;
88import { getStoryName , globalRender , isInvalidStory , objectEntries } from './utils' ;
99
1010// Some addons use the channel api to communicate between manager/preview, and this is a client only feature, therefore we must mock it.
@@ -152,8 +152,9 @@ export function composeStory<GenericArgs extends Args>(
152152 }
153153
154154 const boundPlay = ( { ...extraContext } : TestingStoryPlayContext < GenericArgs > ) => {
155+ const playFn = meta . play ?? story . play ?? ( ( ) => { } ) ;
155156 // @ts -expect-error (just trying to get this to build)
156- return story . play ?. ( { ...context , ...extraContext } ) ;
157+ return playFn ( { ...context , ...extraContext } ) ;
157158 }
158159
159160 composedStory . storyName = story . storyName || story . name
@@ -190,19 +191,17 @@ export function composeStory<GenericArgs extends Args>(
190191 * @param storiesImport - e.g. (import * as stories from './Button.stories')
191192 * @param [globalConfig] - e.g. (import * as globalConfig from '../.storybook/preview') this can be applied automatically if you use `setGlobalConfig` in your setup files.
192193 */
193- export function composeStories <
194- TModule extends StoryFile
195- > ( storiesImport : TModule , globalConfig ?: GlobalConfig ) {
196- const { default : meta , __esModule, ...stories } = storiesImport ;
194+ export function composeStories < TModule extends Store_CSFExports < ReactRenderer > > ( storiesImport : TModule , globalConfig ?: GlobalConfig ) {
195+ const { default : meta , __esModule, __namedExportsOrder, ...stories } = storiesImport ;
197196
198- // This function should take this as input:
197+ // This function should take this as input:
199198 // {
200199 // default: Meta,
201200 // Primary: Story<ButtonProps>, <-- Props extends Args
202201 // Secondary: Story<OtherProps>,
203202 // }
204203
205- // And strips out default, then return composed stories as output:
204+ // And strips out default, then return composed stories as output:
206205 // {
207206 // Primary: ComposedStory<Partial<ButtonProps>>,
208207 // Secondary: ComposedStory<Partial<OtherProps>>,
@@ -229,5 +228,5 @@ export function composeStories<
229228
230229 // @TODO : the inferred type of composedStories is correct but Partial.
231230 // investigate whether we can return an unpartial type of that without this hack
232- return composedStories as unknown as Omit < StoriesWithPartialProps < TModule > , keyof StoryFile > ;
231+ return composedStories as unknown as Omit < StoriesWithPartialProps < TModule > , keyof Store_CSFExports > ;
233232}
0 commit comments