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

Core: StorybookConfig stories-field support type async function #21555

Merged
merged 7 commits into from
Nov 27, 2023

Conversation

imccausl
Copy link
Contributor

@imccausl imccausl commented Mar 10, 2023

Closes #21524

What I did

Modifies to the StorybookConfig['stories'] type to include a function that returns a Promise that resolves to StoriesEntry[]. This should cover the custom implementation case. Since this logic is already supported where presets are loaded/resolved and is already documented, I did not make changes to documentation or add tests.

How to test

  1. modify main.ts in ui/.storybook so that the stories key in the config has an async function that resolves a promise like this:
const asyncStories = Promise.resolve(allStories)
const config: StorybookConfig = {
     stories: async () => [... (await asyncStories)],
     // ...rest of the config
  1. After this modification you should not see a typescript error on the stories key regardless of how you configure stories (async func or as a StoriesEntry array.
  2. run yarn start to run the storybook dev server
  3. all stories should load as expected.

Checklist

  • Make sure your changes are tested (stories and/or unit, integration, or end-to-end tests)
  • Make sure to add/update documentation regarding your changes (updated docstring)
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Maintainers

  • If this PR should be tested against many or all sandboxes,
    make sure to add the ci:merged or ci:daily GH label to it.
  • Make sure this PR contains one of the labels below.

["cleanup", "BREAKING CHANGE", "feature request", "bug", "documentation", "maintenance", "dependencies", "other"]

@imccausl imccausl changed the title Fix stories type add custom implementation type (async function) to StorybookConfig stories type Mar 10, 2023
@ndelangen
Copy link
Member

@shilman I think we need to discuss this...

Perhaps we decide after GA?

This PR seems correct to me..

  • we have documentation saying it should be so
  • we have implementation saying it should be so

Yet our types say not.

We kinda want to have this just be an array, because this value can be modified by codemods (maybe?), and for those to work, we want it to be a simple value.

But considering the above, I think we should merge this as-is, make the types match the documentation & implementation, then figure out how to do better config in the future.
I suspect we'll just have to make codemods smarter/better to cope with this.

@ndelangen ndelangen changed the base branch from next to release-8-0 November 24, 2023 15:19
@ndelangen ndelangen changed the title add custom implementation type (async function) to StorybookConfig stories type Core: StorybookConfig stories type support for type async function Nov 24, 2023
@ndelangen ndelangen changed the title Core: StorybookConfig stories type support for type async function Core: StorybookConfig stories-field support type async function Nov 24, 2023
@ndelangen ndelangen merged commit 41a80df into storybookjs:release-8-0 Nov 27, 2023
48 of 49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: StoriesEntry type does not allow for custom implementation with async function
2 participants