Skip to content

Type the story files with Storybook's CSF types - #2447

Merged
spaceninja merged 1 commit into
mainfrom
type-story-files
Aug 24, 2026
Merged

Type the story files with Storybook's CSF types#2447
spaceninja merged 1 commit into
mainfrom
type-story-files

Conversation

@spaceninja

@spaceninjaspaceninja commented Aug 24, 2026

Copy link
Copy Markdown
Member

Overview

tsconfig.json excluded src/**/*.stories.js, so 70 story files were never type-checked. Removing the exclude surfaced 203 errors. Typing each file's meta as Meta and its stories as StoryObj clears most of them at the source — the render parameter's type flows from the annotation — and the remainder were fixed case by case. The types arrive through a JSDoc @import, because these are .js files and Storybook's glob only picks up .js.

The mechanical sweep is the bulk of the diff and the least interesting part of it. What is worth a reviewer's time is that typing the metas turned up a handful of argTypes that do not match Storybook's API — listed below, because a few of them change what the Controls panel and docs tables do.

Screenshots

Testing

The sweep itself is covered by tsc. These steps are for the API corrections, which are the only changes that can alter what you see:

  • Open the deploy preview and go to Vendor → WordPress → Core Blocks. On the Embed, Group, Image and Media Text stories, open the Controls panel and check the dropdowns — Alignment should offer None, Left, Center, Right, Full, Wide, Ratio should offer 21:9 through 1:2, and Vertical Alignment should offer Top, Center, Bottom. Pick a few and confirm the example re-renders as it does on the production library.
  • On Objects → Deck, the Alignment dropdown should read None, Full, Wide and changing it should still move the cards.
  • On Vendor → WordPress → Utilities, the Font Size control should be a dropdown listing big, small, heading-n-2 and so on. This one is a genuine fix — see below — so compare it against production, where the list may be missing.
  • On Objects → Hype Group, Object Shape should be a dropdown offering circle and square.
  • On Components → Alert and Components → Subscribe, open the Docs tab and check the args table's Default column shows values for dismissable, icon and the paragraphs arg rather than blanks.
  • Click through a sample of other component pages and confirm nothing stopped rendering. The story index is unchanged — same 337 stories, same names — so anything missing would be a surprise.

The API corrections, in detail

Eight options label maps. Several argTypes passed an object to options as a label→value map, which is the Storybook 5/6 spelling. Storybook 10 types it readonly any[] and takes labels from control.labels. The object form still works at runtime — the control does Array.isArray(options) ? … : Object.keys(options) — so this is a spelling change, not a repair. Every label/value pair and its order is preserved, verified by extracting both forms and comparing them pair for pair.

type: { name: 'enum' }, eight occurrences. Malformed: SBEnumType requires a value array. Each of these sits directly beside an options list holding exactly those values, so value now carries the same list. This affects the docs table's Type column, not the control.

fontSizeControlConfig had options nested inside control. Storybook reads the option list off the arg type, not off the control, so it was not finding it. colorControlConfig, ten lines above in the same file, does it correctly — which is what makes this a mistake rather than a convention. This is the one change that may fix a visibly broken control, hence the testing step above.

object_shape: { type: 'select' }.select is a control type in the arg-type slot; type takes a scalar name or an SBType. Now options plus control: { type: 'select' }.

Four table.defaultValue.summary values were a boolean or a number where Storybook wants a string. Their neighbours in the same files already write 'div' and 'Get notifications', so 'false' and '2' follow the local convention.

generateGroundNavProps declared @param {defaultArgs} — a value used as a type. Storybook hands stories a loose args record, so the parameter is now typed as that.

These overlap #2428's territory, since they are mistranslations from the CSF migration. I fixed them here only because they are what the type errors were, and left everything else for that audit.

One correction to the plan

The decision comment expects this to catch bad parameter names — the docs.story.height that #2420 found doing nothing. It does not.Parameters is declared { [name: string]: any }, so anything inside parameters passes; a doubly-misspelled docs.stroy.hieght type-checks clean. What the CSF types do catch is unknown top-level story keys (TS2353), which is how three of the findings above surfaced. Worth knowing before anyone relies on this for parameters.

Scope notes

  • src/prototypes/ is excluded from tsconfig, so its three story files are untouched. One of them still imports with a .ts extension, like the eight fixed here.
  • dist is byte-identical to main, and the built story index is unchanged: the same 337 entries, names and types.

tsconfig excluded src/**/*.stories.js, so 70 story files went unchecked.
Removing the exclude surfaced 203 errors; typing each file's meta as `Meta`
and its stories as `StoryObj` clears most of them at the source, and the
rest were fixed individually. Types come in through a JSDoc `@import`,
since these are `.js` files.
Typing the metas turned up several argTypes that do not match Storybook's
API, which is the part worth reviewing rather than the sweep:
- Eight `options` label maps became an `options` array plus `control.labels`,
the spelling Storybook 10 types. The object form still works at runtime,
and every label/value pair and its order is preserved.
- `type: { name: 'enum' }` is malformed -- `SBEnumType` requires `value` --
so the eight occurrences now carry the same list already in `options`.
- `fontSizeControlConfig` had `options` nested inside `control`, where
Storybook does not look for it. Its sibling in the same file does not.
- `object_shape` used `type: 'select'`, a control type in the arg-type slot.
- Four `table.defaultValue.summary` values were a boolean or a number where
Storybook wants a string, matching what their neighbours already do.
`generateGroundNavProps` also declared `@param {defaultArgs}`, using a value
as a type. Story renders are otherwise untouched; DOM lookups in demo
`useEffect` hooks gained the null guards their types require.
dist is byte-identical and the built story index is unchanged: the same 337
stories, names and types.
Fixes#2429
@changeset-bot

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: fb6c652

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@netlify

netlifyBot commented Aug 24, 2026

Copy link
Copy Markdown

Deploy Preview for cloudfour-patterns ready!

NameLink
🔨 Latest commitfb6c652
🔍 Latest deploy loghttps://app.netlify.com/projects/cloudfour-patterns/deploys/6a8c7e31a4c428000890ce2b
😎 Deploy Previewhttps://deploy-preview-2447--cloudfour-patterns.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@spaceninja
spaceninja merged commit 793f544 into mainAug 24, 2026
8 checks passed
@spaceninja
spaceninja deleted the type-story-files branch August 24, 2026 17:31
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type-check story files

1 participant

@spaceninja