-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Improve type of GlobalTypes to add typed toolbar option #33267
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import type { RemoveIndexSignature, Simplify, UnionToIntersection } from 'type-fest'; | ||
|
|
||
| import type { ToolbarArgType } from '../toolbar'; | ||
| import type { SBScalarType, SBType } from './SBType'; | ||
| import type { CoreTypes } from './core-annotations'; | ||
|
|
||
|
|
@@ -144,6 +145,8 @@ export interface InputType { | |
| [key: string]: any; | ||
| } | ||
|
|
||
| export type { ToolbarArgType }; | ||
|
|
||
| export interface StrictInputType extends InputType { | ||
| name: string; | ||
| type?: SBType; | ||
|
|
@@ -165,10 +168,10 @@ export interface Globals { | |
| [name: string]: any; | ||
| } | ||
| export interface GlobalTypes { | ||
| [name: string]: InputType; | ||
| [name: string]: ToolbarArgType; | ||
| } | ||
|
Comment on lines
170
to
172
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, let's find the file and understand the current state
cd /repo
cat -n code/core/src/csf/story.ts | head -180 | tail -30Repository: storybookjs/storybook Length of output: 1033 🏁 Script executed: # Find InputType and ToolbarArgType definitions
rg -n "type InputType|type ToolbarArgType|interface InputType|interface ToolbarArgType" --type ts -A 3Repository: storybookjs/storybook Length of output: 586 🏁 Script executed: # Find all usages of GlobalTypes
rg -n "GlobalTypes" --type ts -C 2Repository: storybookjs/storybook Length of output: 10410 🏁 Script executed: # Get complete InputType and StrictInputType definitions
rg -n "export.*interface InputType|export.*type InputType|export.*interface StrictInputType|export.*type StrictInputType" --type ts -A 20 | head -100Repository: storybookjs/storybook Length of output: 2856 🏁 Script executed: # Check ToolbarConfig definition
rg -n "type ToolbarConfig|interface ToolbarConfig" --type ts -A 5Repository: storybookjs/storybook Length of output: 432 🏁 Script executed: # Check how normalizeInputTypes handles GlobalTypes
cat -n code/core/src/preview-api/modules/store/csf/normalizeInputTypes.tsRepository: storybookjs/storybook Length of output: 1433 🏁 Script executed: # Search for example globalTypes definitions
rg -n "globalTypes.*=" --type ts -A 3 | head -80Repository: storybookjs/storybook Length of output: 4268 🏁 Script executed: # Search for any migration notes or documentation about this change
fd -e md | xargs rg -l "globalTypes|GlobalTypes" | head -10Repository: storybookjs/storybook Length of output: 292 🏁 Script executed: # Check the example of globalTypes definition
cat -n code/core/template/stories/preview.ts | sed -n '52,70p'Repository: storybookjs/storybook Length of output: 759 🏁 Script executed: # Check the documented snippet for globalTypes
cat docs/_snippets/storybook-preview-configure-globaltypes.mdRepository: storybookjs/storybook Length of output: 2957 🏁 Script executed: # Check MIGRATION.md for any notes about GlobalTypes changes
rg -n "GlobalTypes|globalTypes" MIGRATION.md -B 2 -A 2Repository: storybookjs/storybook Length of output: 1329 Backward compatibility broken by required Changing All documented examples and template code include 🤖 Prompt for AI Agents |
||
| export interface StrictGlobalTypes { | ||
| [name: string]: StrictInputType; | ||
| [name: string]: StrictInputType & ToolbarArgType; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not particularly happy about this one either to be honest. Should |
||
| } | ||
|
|
||
| export interface AddonTypes { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ import type { | |
| NormalizedProjectAnnotations, | ||
| ProjectAnnotations, | ||
| Renderer, | ||
| StrictGlobalTypes, | ||
| } from 'storybook/internal/types'; | ||
|
|
||
| import { inferArgTypes } from '../inferArgTypes'; | ||
|
|
@@ -27,7 +28,7 @@ export function normalizeProjectAnnotations<TRenderer extends Renderer>({ | |
| }: ProjectAnnotations<TRenderer>): NormalizedProjectAnnotations<TRenderer> { | ||
| return { | ||
| ...(argTypes && { argTypes: normalizeInputTypes(argTypes as ArgTypes) }), | ||
| ...(globalTypes && { globalTypes: normalizeInputTypes(globalTypes) }), | ||
| ...(globalTypes && { globalTypes: normalizeInputTypes(globalTypes) as StrictGlobalTypes }), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # Find the normalizeInputTypes function definition and check its return type
ast-grep --pattern 'function normalizeInputTypes($$$) {
$$$
}'Repository: storybookjs/storybook Length of output: 47 🏁 Script executed: # Search for normalizeInputTypes usage and context
rg -n "normalizeInputTypes" --type ts -A 3 -B 3Repository: storybookjs/storybook Length of output: 7572 🏁 Script executed: # Find the StrictGlobalTypes type definition
rg -n "type StrictGlobalTypes" --type ts -A 5Repository: storybookjs/storybook Length of output: 47 🏁 Script executed: # Check the file structure around line 31
cat -n code/core/src/preview-api/modules/store/csf/normalizeProjectAnnotations.ts | sed -n '1,50p'Repository: storybookjs/storybook Length of output: 2713 🏁 Script executed: # Find type definitions for ArgTypes, GlobalTypes, StrictArgTypes, StrictGlobalTypes
rg -n "type (ArgTypes|GlobalTypes|StrictArgTypes|StrictGlobalTypes)" --type tsRepository: storybookjs/storybook Length of output: 1033 🏁 Script executed: # Check the normalizeInputTypes implementation more closely
cat -n code/core/src/preview-api/modules/store/csf/normalizeInputTypes.ts | head -50Repository: storybookjs/storybook Length of output: 1433 🏁 Script executed: # Look at the normalizeInputType function to understand the logic
cat -n code/core/src/preview-api/modules/store/csf/normalizeInputTypes.tsRepository: storybookjs/storybook Length of output: 1433 🏁 Script executed: # Check if there are any type overloads or declarations for normalizeInputTypes
rg -n "declare.*normalizeInputTypes|overload.*normalizeInputTypes" --type tsRepository: storybookjs/storybook Length of output: 47 🏁 Script executed: # Find the type definitions for ArgTypes and GlobalTypes
rg -n "export type ArgTypes|export type GlobalTypes|export type StrictArgTypes|export type StrictGlobalTypes" --type ts -A 1Repository: storybookjs/storybook Length of output: 715 🏁 Script executed: # Also check if there are interface definitions
rg -n "export interface (ArgTypes|GlobalTypes|StrictArgTypes|StrictGlobalTypes)" --type tsRepository: storybookjs/storybook Length of output: 468 🏁 Script executed: # Get the full type definitions
cat -n code/core/src/csf/story.ts | sed -n '164,180p'Repository: storybookjs/storybook Length of output: 658 🏁 Script executed: # Check if GlobalTypes and ArgTypes are structurally compatible
cat -n code/core/src/csf/story.ts | sed -n '164,195p'Repository: storybookjs/storybook Length of output: 1230 🏁 Script executed: # Look at the issue comment in the code - there seems to be a TODO around line 14-17
git log --oneline code/core/src/preview-api/modules/store/csf/normalizeProjectAnnotations.ts | head -20Repository: storybookjs/storybook Length of output: 126 🏁 Script executed: # Find ToolbarArgType definition
rg -n "type ToolbarArgType|interface ToolbarArgType" --type ts -A 3Repository: storybookjs/storybook Length of output: 273 🏁 Script executed: # Check InputType and StrictInputType definitions to understand the difference
rg -n "export type InputType|export type StrictInputType" --type ts -A 2Repository: storybookjs/storybook Length of output: 47 🏁 Script executed: # Search for InputType and StrictInputType definitions more broadly
rg -n "export type InputType|export type StrictInputType|export interface InputType|export interface StrictInputType" --type tsRepository: storybookjs/storybook Length of output: 208 🏁 Script executed: # Check what ToolbarArgType extends/uses
cat -n code/core/src/toolbar/types.ts | head -60Repository: storybookjs/storybook Length of output: 1774 🏁 Script executed: # Check the InputType and StrictInputType definitions
cat -n code/core/src/csf/story.ts | sed -n '111,160p'Repository: storybookjs/storybook Length of output: 2159 🏁 Script executed: # Check what types argTypes and globalTypes have in ProjectAnnotations
rg -n "interface ProjectAnnotations|type ProjectAnnotations" --type ts -A 15Repository: storybookjs/storybook Length of output: 2934 🏁 Script executed: # Find BaseAnnotations to see the types of argTypes and globalTypes
rg -n "interface BaseAnnotations|type BaseAnnotations" --type ts -A 20Repository: storybookjs/storybook Length of output: 2452 🏁 Script executed: # Also check NormalizedProjectAnnotations more fully
cat -n code/core/src/types/modules/story.ts | sed -n '55,65p'Repository: storybookjs/storybook Length of output: 534 🏁 Script executed: # Find argTypes and globalTypes properties in BaseAnnotations/ProjectAnnotations
cat -n code/core/src/csf/story.ts | sed -n '331,405p'Repository: storybookjs/storybook Length of output: 3412 🏁 Script executed: # Check if globalTypes is defined in ProjectAnnotations
cat -n code/core/src/csf/story.ts | sed -n '405,460p'Repository: storybookjs/storybook Length of output: 3112 🏁 Script executed: # Check what properties are actually preserved by normalizeInputType
cat -n code/core/src/preview-api/modules/store/csf/normalizeInputTypes.tsRepository: storybookjs/storybook Length of output: 1433 🏁 Script executed: # Check if there are any related issues or PRs mentioning this
git log --all --oneline --grep="GlobalTypes\|normalizeInputTypes" | head -20Repository: storybookjs/storybook Length of output: 147 🏁 Script executed: # Check the tests to understand the expected behavior
cat -n code/core/src/preview-api/modules/store/csf/normalizeInputTypes.test.ts | sed -n '68,100p'Repository: storybookjs/storybook Length of output: 471 Add function overloads to The type assertion
This would eliminate the need for the output cast and improve type safety throughout the codebase. 🤖 Prompt for AI Agents |
||
| decorators: normalizeArrays(decorators), | ||
| loaders: normalizeArrays(loaders), | ||
| beforeEach: normalizeArrays(beforeEach), | ||
|
|
||
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.
Not sure about where this should be exported from, but it should be exported.