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

[Bug]: Types are missing/unavailable for options.storySort #22779

Open
kaiyoma opened this issue May 25, 2023 · 3 comments
Open

[Bug]: Types are missing/unavailable for options.storySort #22779

kaiyoma opened this issue May 25, 2023 · 3 comments

Comments

@kaiyoma
Copy link

kaiyoma commented May 25, 2023

Describe the bug

Even if I apply the Preview type (from @storybook/react), TypeScript doesn't know the types of the arguments to storySort:

preview.ts:33:17 - error TS7006: Parameter 'a' implicitly has an 'any' type.

33     storySort: (a, b) => {
                   ~

preview.ts:33:20 - error TS7006: Parameter 'b' implicitly has an 'any' type.

33     storySort: (a, b) => {
                      ~

The migration guide says that these arguments are of type StoryIndexEntry, but I can't find this type in the Storybook packages. I shouldn't even need to, because storySort should already have the correct types assigned to it.

To Reproduce

import type { Preview } from '@storybook/react';

export default <Preview>{
  options: {
    storySort: (a, b) => {
      return a.title === b.title ? 0 : a.id.localeCompare(b.id, undefined, { numeric: true });
    },
  },
};

System

Environment Info:

  System:
    OS: Windows 10 10.0.22621
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
  Binaries:
    Node: 16.19.1 - C:\Program Files\Node.js\node.EXE
    npm: 9.6.2 - C:\Program Files\Node.js\npm.CMD
  Browsers:
    Edge: Spartan (44.22621.1702.0), Chromium (113.0.1774.50)
  npmPackages:
    @storybook/addon-actions: 7.0.17 => 7.0.17
    @storybook/addon-controls: 7.0.17 => 7.0.17
    @storybook/addon-docs: 7.0.17 => 7.0.17
    @storybook/addons: 7.0.17 => 7.0.17
    @storybook/api: 7.0.17 => 7.0.17
    @storybook/components: 7.0.17 => 7.0.17
    @storybook/core-events: 7.0.17 => 7.0.17
    @storybook/react: 7.0.17 => 7.0.17
    @storybook/react-vite: 7.0.17 => 7.0.17
    @storybook/theming: 7.0.17 => 7.0.17

Additional context

No response

@shilman
Copy link
Member

shilman commented May 25, 2023

We should fix that. There are types for that here: https://github.com/storybookjs/storybook/blob/next/code/lib/types/src/modules/csf.ts#L67-L71

I'm not sure what work is required to hook that up across all the different renderers. @kasperpeulen thoughts?

@kaiyoma
Copy link
Author

kaiyoma commented Jul 3, 2023

Another issue here. If I add types manually, like this:

    options: {
      storySort: (a: StoryIndexEntry, b: StoryIndexEntry): number => {
        return a.id === b.id ? 0 : a.id.localeCompare(b.id, undefined, { numeric: true });
      },
    },

and then try to build Storybook, it bails with a parsing error:

WARN 🚨 SyntaxError: Unexpected token ':'
ERR! SyntaxError: Unexpected token ':'
ERR!     at eval (<anonymous>)
ERR!     at getStorySortParameter (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+csf-tools@7.1.0-alpha.41\node_modules\@storybook\csf-tools\dist\index.js:28:1772)
ERR!     at StoryIndexGenerator.getStorySortParameter (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+core-server@7.1.0-alpha.41\node_modules\@storybook\core-server\dist\index.js:65:5850)
ERR!     at async StoryIndexGenerator.sortStories (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+core-server@7.1.0-alpha.41\node_modules\@storybook\core-server\dist\index.js:65:3060)
ERR!     at async StoryIndexGenerator.getIndex (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+core-server@7.1.0-alpha.41\node_modules\@storybook\core-server\dist\index.js:65:3920)
ERR!     at async extractStoriesJson (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+core-server@7.1.0-alpha.41\node_modules\@storybook\core-server\dist\index.js:57:4535)
ERR!     at async Promise.all (index 3)
ERR!     at async buildStaticStandalone (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+core-server@7.1.0-alpha.41\node_modules\@storybook\core-server\dist\index.js:109:1799)
ERR!     at async withTelemetry (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+core-server@7.1.0-alpha.41\node_modules\@storybook\core-server\dist\index.js:113:3620)
ERR!     at async build (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+cli@7.1.0-alpha.41\node_modules\@storybook\cli\dist\generate.js:435:1059)
ERR!  SyntaxError: Unexpected token ':'
ERR!     at eval (<anonymous>)
ERR!     at getStorySortParameter (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+csf-tools@7.1.0-alpha.41\node_modules\@storybook\csf-tools\dist\index.js:28:1772)
ERR!     at StoryIndexGenerator.getStorySortParameter (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+core-server@7.1.0-alpha.41\node_modules\@storybook\core-server\dist\index.js:65:5850)
ERR!     at async StoryIndexGenerator.sortStories (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+core-server@7.1.0-alpha.41\node_modules\@storybook\core-server\dist\index.js:65:3060)
ERR!     at async StoryIndexGenerator.getIndex (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+core-server@7.1.0-alpha.41\node_modules\@storybook\core-server\dist\index.js:65:3920)
ERR!     at async extractStoriesJson (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+core-server@7.1.0-alpha.41\node_modules\@storybook\core-server\dist\index.js:57:4535)
ERR!     at async Promise.all (index 3)
ERR!     at async buildStaticStandalone (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+core-server@7.1.0-alpha.41\node_modules\@storybook\core-server\dist\index.js:109:1799)
ERR!     at async withTelemetry (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+core-server@7.1.0-alpha.41\node_modules\@storybook\core-server\dist\index.js:113:3620)
ERR!     at async build (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+cli@7.1.0-alpha.41\node_modules\@storybook\cli\dist\generate.js:435:1059)
WARN 🚨 SyntaxError: Unexpected token ':'

@kasperpeulen kasperpeulen self-assigned this Jul 13, 2023
@kdssoftware
Copy link

Another issue here. If I add types manually, like this:

    options: {
      storySort: (a: StoryIndexEntry, b: StoryIndexEntry): number => {
        return a.id === b.id ? 0 : a.id.localeCompare(b.id, undefined, { numeric: true });
      },
    },

and then try to build Storybook, it bails with a parsing error:

WARN 🚨 SyntaxError: Unexpected token ':'
ERR! SyntaxError: Unexpected token ':'
ERR!     at eval (<anonymous>)
ERR!     at getStorySortParameter (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+csf-tools@7.1.0-alpha.41\node_modules\@storybook\csf-tools\dist\index.js:28:1772)
ERR!     at StoryIndexGenerator.getStorySortParameter (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+core-server@7.1.0-alpha.41\node_modules\@storybook\core-server\dist\index.js:65:5850)
ERR!     at async StoryIndexGenerator.sortStories (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+core-server@7.1.0-alpha.41\node_modules\@storybook\core-server\dist\index.js:65:3060)
ERR!     at async StoryIndexGenerator.getIndex (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+core-server@7.1.0-alpha.41\node_modules\@storybook\core-server\dist\index.js:65:3920)
ERR!     at async extractStoriesJson (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+core-server@7.1.0-alpha.41\node_modules\@storybook\core-server\dist\index.js:57:4535)
ERR!     at async Promise.all (index 3)
ERR!     at async buildStaticStandalone (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+core-server@7.1.0-alpha.41\node_modules\@storybook\core-server\dist\index.js:109:1799)
ERR!     at async withTelemetry (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+core-server@7.1.0-alpha.41\node_modules\@storybook\core-server\dist\index.js:113:3620)
ERR!     at async build (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+cli@7.1.0-alpha.41\node_modules\@storybook\cli\dist\generate.js:435:1059)
ERR!  SyntaxError: Unexpected token ':'
ERR!     at eval (<anonymous>)
ERR!     at getStorySortParameter (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+csf-tools@7.1.0-alpha.41\node_modules\@storybook\csf-tools\dist\index.js:28:1772)
ERR!     at StoryIndexGenerator.getStorySortParameter (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+core-server@7.1.0-alpha.41\node_modules\@storybook\core-server\dist\index.js:65:5850)
ERR!     at async StoryIndexGenerator.sortStories (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+core-server@7.1.0-alpha.41\node_modules\@storybook\core-server\dist\index.js:65:3060)
ERR!     at async StoryIndexGenerator.getIndex (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+core-server@7.1.0-alpha.41\node_modules\@storybook\core-server\dist\index.js:65:3920)
ERR!     at async extractStoriesJson (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+core-server@7.1.0-alpha.41\node_modules\@storybook\core-server\dist\index.js:57:4535)
ERR!     at async Promise.all (index 3)
ERR!     at async buildStaticStandalone (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+core-server@7.1.0-alpha.41\node_modules\@storybook\core-server\dist\index.js:109:1799)
ERR!     at async withTelemetry (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+core-server@7.1.0-alpha.41\node_modules\@storybook\core-server\dist\index.js:113:3620)
ERR!     at async build (C:\Users\kgetz\Work\event-viewer\node_modules\.pnpm\@storybook+cli@7.1.0-alpha.41\node_modules\@storybook\cli\dist\generate.js:435:1059)
WARN 🚨 SyntaxError: Unexpected token ':'

You can't add types according to the docs https://storybook.js.org/docs/writing-stories/naming-components-and-hierarchy#sorting-stories
// Theaandbarguments in this function have a type ofimport('@storybook/types').IndexEntry. Remember that the function is executed in a JavaScript environment, so use JSDoc for IntelliSense to introspect it.

Using ts-ignore removes Typescript warning.

        // @ts-ignore
        storySort: (a, b) => //...

Works for me this way.

@vanessayuenn vanessayuenn added this to the 8.0-RC milestone Jan 9, 2024
@shilman shilman added sev:S3 and removed sev:S2 labels Jan 26, 2024
@vanessayuenn vanessayuenn modified the milestones: 8.0-RC, 8.0-nice to have Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Empathy Backlog
Status: No status
Development

No branches or pull requests

5 participants