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: Typesafe parameters #30601

Open
wants to merge 4 commits into
base: next
Choose a base branch
from
Open

Core: Typesafe parameters #30601

wants to merge 4 commits into from

Conversation

kasperpeulen
Copy link
Contributor

@kasperpeulen kasperpeulen commented Feb 20, 2025

Closes #

What I did

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>

Greptile Summary

Enhanced type safety across Storybook addons by introducing consistent parameter typing and addon definition patterns.

  • Replaced definePreview with definePreviewAddon from storybook/internal/csf for better type inference
  • Added new *Types interfaces (e.g. A11yTypes, ActionsTypes) to wrap parameters and globals for each addon
  • Made configuration parameters optional with ? modifier for better flexibility
  • Introduced PreviewAddon interface and InferTypes utility in csf-factories.ts for improved addon type safety
  • Updated Next.js framework integrations to support the new typesafe parameter system

Copy link

nx-cloud bot commented Feb 20, 2025

View your CI Pipeline Execution ↗ for commit 526ce10.

Command Status Duration Result
nx run-many -t build --parallel=3 ✅ Succeeded 2m View ↗

☁️ Nx Cloud last updated this comment at 2025-02-20 16:44:18 UTC

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

37 file(s) reviewed, 14 comment(s)
Edit PR Review Bot Settings | Greptile

@@ -26,6 +26,7 @@ import { definePreview } from '@storybook/react-vite';

import addonA11y from '@storybook/addon-a11y';
import addonEssentials from '@storybook/addon-essentials';
import addonHighlight from '@storybook/addon-highlight';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: addonHighlight is imported but never used in the configuration

Suggested change
import addonHighlight from '@storybook/addon-highlight';

@@ -1,7 +1,9 @@
import { definePreviewAddon } from 'storybook/internal/csf';
import { definePreview } from 'storybook/internal/preview-api';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: definePreview is imported but never used - should be removed

Suggested change
import { definePreview } from 'storybook/internal/preview-api';

import type { ActionsTypes } from '@storybook/addon-actions';
import type { BackgroundTypes } from '@storybook/addon-backgrounds';
import type { DocsTypes } from '@storybook/addon-docs';
import type { HighLightTypes } from '@storybook/addon-highlight';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax: Inconsistent casing - imported as 'HighLightTypes' but defined as 'HighlightTypes' in the source file

Suggested change
import type { HighLightTypes } from '@storybook/addon-highlight';
import type { HighlightTypes } from '@storybook/addon-highlight';

Comment on lines +13 to +14
export interface HighLightTypes {
parameters: HighlightParameters;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax: inconsistent casing - 'HighLightTypes' should be 'HighlightTypes' to match the casing of HighlightParameters

Suggested change
export interface HighLightTypes {
parameters: HighlightParameters;
export interface HighlightTypes {
parameters: HighlightParameters;

@@ -1,5 +1,9 @@
import { definePreviewAddon } from 'storybook/internal/csf';
import { definePreview } from 'storybook/internal/preview-api';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: definePreview import is no longer used and can be removed

Suggested change
import { definePreview } from 'storybook/internal/preview-api';

Comment on lines +41 to +50
interface Animal {
animalStuff: any;
}
interface Dog extends Types {
dogStuff: any;
}

interface Bla extends Types {
blaStuff: any;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Duplicate interface definitions for Animal - one at line 41 and another at line 54


const c = [handleAnimal, handleDog];

type A = typeof c extends Type<infer T>[] ? T: never;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Type alias 'A' is redefined - conflicts with previous definition on line 27

return definePreviewBase({
...preview,
addons: [nextPreview, ...(preview.addons ?? [])],
}) as NextPreview;
}) as unknown as NextPreview<InferTypes<Addons>>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Double type assertion (as unknown as) may hide type errors. Consider refactoring to avoid this pattern.

ReactRenderer & NextJsTypes & InferTypes<Addons>
>
): NextPreview<InferTypes<Addons>> {
// @ts-expect-error hard
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Generic ts-expect-error comment needs more specific explanation of why this type error is expected and can't be fixed

return definePreviewBase({
...preview,
addons: [nextPreview, ...(preview.addons ?? [])],
}) as NextPreview;
}) as unknown as NextPreview<InferTypes<Addons>>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Double type assertion (as unknown as) is dangerous and could mask real type errors. Consider restructuring to avoid this

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.

1 participant