storybookjs/storybook

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

已关闭

#21,524 创建于 2023年3月9日

 (4 条评论) (1 个反应) (2 位负责人)TypeScript (10,058 个派生)batch import
bugcoregood first issuehas workaroundsev:S3typescript

仓库指标

星标
 (89,909 个星标)
PR 合并指标
 (平均合并 7天 22小时) (30 天内合并 184 个 PR)

描述

Describe the bug

In the storybook docs, there is an example where you can pass in an async function to stories to implement custom logic for loading stories. This works as expected, but if you are using typescript, it gives the error Type '() => Promise<string[]>' is not assignable to type 'StoriesEntry[]'.

To Reproduce

This config will produce the typescript error, although it is a valid way to construct a stories configuration, according to the docs.

import type { StorybookConfig } from '@storybook/react-webpack5';

const stories = Promise.resolve(['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'])
const config: StorybookConfig = {
  stories: async () => [...await stories],
  addons: [
    '@storybook/addon-links',
    '@storybook/addon-essentials',
    '@storybook/addon-interactions',
  ],
  framework: {
    name: '@storybook/react-webpack5',
    options: {},
  },
  docs: {
    autodocs: 'tag',
  },
};
export default config;

System

System:
    OS: macOS 13.2.1
    CPU: (8) arm64 Apple M1 Pro
  Binaries:
    Node: 18.14.2 - ~/.nvm/versions/node/v18.14.2/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.14.2/bin/yarn
    npm: 9.5.0 - ~/.nvm/versions/node/v18.14.2/bin/npm
  Browsers:
    Chrome: 110.0.5481.177
    Firefox: 109.0
    Safari: 16.3
  npmPackages:
    @storybook/addon-essentials: ^7.0.0-beta.64 => 7.0.0-rc.0
    @storybook/addon-interactions: ^7.0.0-beta.64 => 7.0.0-rc.0
    @storybook/addon-links: ^7.0.0-beta.64 => 7.0.0-rc.0
    @storybook/blocks: ^7.0.0-beta.64 => 7.0.0-rc.0
    @storybook/react: ^7.0.0-beta.64 => 7.0.0-rc.0
    @storybook/react-webpack5: ^7.0.0-beta.64 => 7.0.0-rc.0
    @storybook/testing-library: ^0.0.14-next.1 => 0.0.14-next.1

Additional context

I am willing to submit a fix to the StoriesEntry type for this.

贡献者指南