-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
base: next
Are you sure you want to change the base?
Core: Typesafe parameters #30601
Conversation
# Conflicts: # code/core/src/csf/csf-factories.ts
View your CI Pipeline Execution ↗ for commit 526ce10.
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this 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
code/.storybook/preview.tsx
Outdated
@@ -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'; |
There was a problem hiding this comment.
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
import addonHighlight from '@storybook/addon-highlight'; |
@@ -1,7 +1,9 @@ | |||
import { definePreviewAddon } from 'storybook/internal/csf'; | |||
import { definePreview } from 'storybook/internal/preview-api'; |
There was a problem hiding this comment.
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
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'; |
There was a problem hiding this comment.
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
import type { HighLightTypes } from '@storybook/addon-highlight'; | |
import type { HighlightTypes } from '@storybook/addon-highlight'; |
export interface HighLightTypes { | ||
parameters: HighlightParameters; |
There was a problem hiding this comment.
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
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'; |
There was a problem hiding this comment.
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
import { definePreview } from 'storybook/internal/preview-api'; |
interface Animal { | ||
animalStuff: any; | ||
} | ||
interface Dog extends Types { | ||
dogStuff: any; | ||
} | ||
|
||
interface Bla extends Types { | ||
blaStuff: any; | ||
} |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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>>; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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>>; |
There was a problem hiding this comment.
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
Closes #
What I did
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal
,ci:merged
orci:daily
GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/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.
definePreview
withdefinePreviewAddon
fromstorybook/internal/csf
for better type inference*Types
interfaces (e.g.A11yTypes
,ActionsTypes
) to wrap parameters and globals for each addon?
modifier for better flexibilityPreviewAddon
interface andInferTypes
utility incsf-factories.ts
for improved addon type safety