Skip to content

React: Preserve @ts-expect-error in preview#32442

Merged
ndelangen merged 2 commits into
storybookjs:nextfrom
mrginglymus:preserve-expect-error
Sep 16, 2025
Merged

React: Preserve @ts-expect-error in preview#32442
ndelangen merged 2 commits into
storybookjs:nextfrom
mrginglymus:preserve-expect-error

Conversation

@mrginglymus
Copy link
Copy Markdown
Contributor

@mrginglymus mrginglymus commented Sep 11, 2025

What I did

Switched the @ts-expect-error comments from inline // to docstring /** */. The former typescript discards, the latter it preserves.

This ensures that those with skipLibCheck: false do not get errors.

I did spend considerable time trying to work out why there was an error but got stuck in a complete typing quagmire. It seems that the arg types are passed around in three separate places - as Renderer['T'], Renderer['args'] and also as a second TArgs type argument to many methods.

Checklist for Contributors

Testing

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

Manual testing

The react sandbox should now be type checkable with skipLibCheck: false

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 pull request has been released as version 0.0.0-pr-32442-sha-22d82d2d. Try it out in a new sandbox by running npx storybook@0.0.0-pr-32442-sha-22d82d2d sandbox or in an existing project with npx storybook@0.0.0-pr-32442-sha-22d82d2d upgrade.

More information
Published version 0.0.0-pr-32442-sha-22d82d2d
Triggered by @ndelangen
Repository mrginglymus/storybook
Branch preserve-expect-error
Commit 22d82d2d
Datetime Mon Sep 15 13:48:29 UTC 2025 (1757944109)
Workflow run 17735330500

To request a new release of this pull request, mention the @storybookjs/core team.

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

Greptile Summary

Updated On: 2025-09-11 15:59:12 UTC

This PR addresses a TypeScript compilation issue in the React renderer by converting three @ts-expect-error comments from inline (//) format to JSDoc (/** */) format. The change is made in code/renderers/react/src/preview.tsx at lines 51, 84, and 108.

The core issue stems from TypeScript's behavior when compiling code: inline comments are discarded during compilation, while JSDoc comments are preserved. This creates problems for users who have skipLibCheck: false in their TypeScript configuration, as they encounter type errors that should be suppressed.

The affected locations contain complex interface definitions involving the React renderer's type system, where there are intricate relationships between Renderer['T'], Renderer['args'], and TArgs type parameters. These create unavoidable type conflicts that require error suppression. Rather than attempting to resolve the underlying type complexity (which the author describes as a "typing quagmire"), this pragmatic solution ensures the error suppressions persist through compilation.

This change integrates well with Storybook's broader architecture by maintaining the existing type safety mechanisms while ensuring compatibility with stricter TypeScript configurations. The modification is minimal and surgical, preserving all existing functionality while solving the compilation issue.

Confidence score: 5/5

  • This PR is safe to merge with minimal risk
  • Score reflects the surgical nature of the change and clear understanding of the TypeScript compilation issue
  • No files require special attention as the changes are straightforward comment format conversions

Copy link
Copy Markdown
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.

Reviewing changes made in this pull request

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Sep 11, 2025

View your CI Pipeline Execution ↗ for commit 22d82d2

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

☁️ Nx Cloud last updated this comment at 2025-09-15 14:13:04 UTC

@vanessayuenn
Copy link
Copy Markdown
Contributor

@ndelangen please make a canary release for this PR to test it out.

@mrginglymus
Copy link
Copy Markdown
Contributor Author

mrginglymus commented Sep 15, 2025

@ndelangen thanks, canary works great - patch no longer required to support skipLibCheck: false. Any chance of getting this into 9.1?

@ndelangen ndelangen merged commit f968cc9 into storybookjs:next Sep 16, 2025
58 of 60 checks passed
@mrginglymus mrginglymus deleted the preserve-expect-error branch September 16, 2025 06:43
@cdedreuille
Copy link
Copy Markdown
Contributor

cdedreuille commented Sep 16, 2025

@ndelangen @vanessayuenn - Hello 👋 - Can this change the patched on Storybook 9? We had the issue there and we are not ready to test Storybook 10.

@vanessayuenn vanessayuenn added the patch:yes Bugfix & documentation PR that need to be picked to main branch label Sep 16, 2025
@storybook-app-bot
Copy link
Copy Markdown

Package Benchmarks

Commit: 22d82d2, ran on 16 September 2025 at 21:24:02 UTC

The following packages have significant changes to their size or dependencies:

@storybook/addon-docs

Before After Difference
Dependency count 18 18 0
Self size 2.06 MB 2.01 MB 🎉 -50 KB 🎉
Dependency size 9.43 MB 9.43 MB 🚨 +6 KB 🚨
Bundle Size Analyzer Link Link

@storybook/builder-vite

Before After Difference
Dependency count 11 11 0
Self size 319 KB 374 KB 🚨 +55 KB 🚨
Dependency size 1.30 MB 1.30 MB 🎉 -18 B 🎉
Bundle Size Analyzer Link Link

storybook

Before After Difference
Dependency count 48 48 0
Self size 30.11 MB 30.42 MB 🚨 +302 KB 🚨
Dependency size 17.64 MB 17.65 MB 🚨 +6 KB 🚨
Bundle Size Analyzer Link Link

@storybook/html-vite

Before After Difference
Dependency count 14 14 0
Self size 23 KB 23 KB 🚨 +18 B 🚨
Dependency size 1.66 MB 1.71 MB 🚨 +55 KB 🚨
Bundle Size Analyzer Link Link

@storybook/nextjs

Before After Difference
Dependency count 529 529 0
Self size 939 KB 928 KB 🎉 -12 KB 🎉
Dependency size 58.64 MB 58.63 MB 🎉 -6 KB 🎉
Bundle Size Analyzer Link Link

@storybook/nextjs-vite

Before After Difference
Dependency count 124 130 🚨 +6 🚨
Self size 4.01 MB 4.00 MB 🎉 -12 KB 🎉
Dependency size 21.58 MB 21.66 MB 🚨 +79 KB 🚨
Bundle Size Analyzer Link Link

@storybook/preact-vite

Before After Difference
Dependency count 14 14 0
Self size 14 KB 14 KB 🎉 -18 B 🎉
Dependency size 1.64 MB 1.70 MB 🚨 +55 KB 🚨
Bundle Size Analyzer Link Link

@storybook/react-native-web-vite

Before After Difference
Dependency count 157 163 🚨 +6 🚨
Self size 31 KB 31 KB 🚨 +24 B 🚨
Dependency size 22.97 MB 23.05 MB 🚨 +79 KB 🚨
Bundle Size Analyzer Link Link

@storybook/react-vite

Before After Difference
Dependency count 114 120 🚨 +6 🚨
Self size 36 KB 36 KB 🚨 +1 B 🚨
Dependency size 19.52 MB 19.60 MB 🚨 +79 KB 🚨
Bundle Size Analyzer Link Link

@storybook/svelte-vite

Before After Difference
Dependency count 22 22 0
Self size 59 KB 59 KB 🎉 -18 B 🎉
Dependency size 26.89 MB 26.95 MB 🚨 +55 KB 🚨
Bundle Size Analyzer Link Link

@storybook/sveltekit

Before After Difference
Dependency count 23 23 0
Self size 49 KB 49 KB 🚨 +60 B 🚨
Dependency size 26.95 MB 27.01 MB 🚨 +55 KB 🚨
Bundle Size Analyzer Link Link

@storybook/vue3-vite

Before After Difference
Dependency count 109 110 🚨 +1 🚨
Self size 38 KB 38 KB 🚨 +77 B 🚨
Dependency size 43.76 MB 43.82 MB 🚨 +63 KB 🚨
Bundle Size Analyzer Link Link

@storybook/web-components-vite

Before After Difference
Dependency count 15 15 0
Self size 20 KB 20 KB 0 B
Dependency size 1.68 MB 1.74 MB 🚨 +55 KB 🚨
Bundle Size Analyzer Link Link

@storybook/cli

Before After Difference
Dependency count 192 205 🚨 +13 🚨
Self size 886 KB 886 KB 🎉 -462 B 🎉
Dependency size 80.05 MB 81.72 MB 🚨 +1.67 MB 🚨
Bundle Size Analyzer Link Link

@storybook/codemod

Before After Difference
Dependency count 174 174 0
Self size 35 KB 35 KB 🎉 -42 B 🎉
Dependency size 76.48 MB 76.79 MB 🚨 +308 KB 🚨
Bundle Size Analyzer Link Link

create-storybook

Before After Difference
Dependency count 49 49 0
Self size 1.55 MB 1.52 MB 🎉 -24 KB 🎉
Dependency size 47.76 MB 48.06 MB 🚨 +308 KB 🚨
Bundle Size Analyzer node node

@storybook/preset-react-webpack

Before After Difference
Dependency count 170 170 0
Self size 21 KB 26 KB 🚨 +6 KB 🚨
Dependency size 30.84 MB 30.84 MB 🚨 +6 B 🚨
Bundle Size Analyzer Link Link

@storybook/react

Before After Difference
Dependency count 2 2 0
Self size 884 KB 872 KB 🎉 -12 KB 🎉
Dependency size 18 KB 18 KB 0 B
Bundle Size Analyzer Link Link

@github-actions github-actions Bot mentioned this pull request Sep 17, 2025
5 tasks
ndelangen added a commit that referenced this pull request Sep 18, 2025
React: Preserve `@ts-expect-error` in preview
(cherry picked from commit f968cc9)
@github-actions github-actions Bot added the patch:done Patch/release PRs already cherry-picked to main/release branch label Sep 18, 2025
@ndelangen ndelangen removed the patch:yes Bugfix & documentation PR that need to be picked to main branch label Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug ci:normal patch:done Patch/release PRs already cherry-picked to main/release branch react typescript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants