Repository navigation
perf(types): faster type-checking for annotated styled component exports - #5801
Conversation
🦋 Changeset detectedLatest commit: 0251fa1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — PolymorphicComponent switches its exotic base from React.ForwardRefExoticComponent to React.NamedExoticComponent so explicit declaration-site annotations (StyledComponent<Target, Props> / IStyledComponent<...>) stop walking ~265-key mapped members (defaultProps?: Partial<P>, propTypes) in both directions under the invariant Props. defaultProps is re-declared with the real narrow shape in IStyledComponentBase, so only the deprecated propTypes typing is given up. Consumer and augment type-perf budgets were re-measured (-10.2% / -9.5% instantiations); docs/type-performance.md documents the residual Partial<Props> walk and why attrs/defaultProps precision is deliberately retained; withTheme's ForwardRefExoticComponent base is correctly left unchanged.
I verified each load-bearing claim directly rather than relying on the benchmarks alone:
- Only
propTypesis actually dropped.React.ForwardRefExoticComponent<P>adds a single member overNamedExoticComponent<P>(propTypesunder @types/react 19;defaultProps+propTypesunder the 18 baseline).IStyledComponentBasere-declaresdefaultProps?: (ExecutionProps & Partial<Props>), and neitherIStyledStaticsnorCommonStaticsdeclarespropTypes, so nothing else is silently lost. - Ref forwarding is preserved. For a value-component type,
ComponentPropsWithRef<T>falls through to the call-signaturePropsregardless of the exotic base (both bases are non-newable), andComponentRef<StyledComponent<...>>already resolved toneverbefore this change. The real ref typing rides inComponentTargetPropsviaReact.ComponentPropsWithRef<Target>over the target element, which the change never touches. - Exactness is preserved. The swap is symmetric (both the constructor output and the annotation derive from
PolymorphicComponent), and the_scExactmutual-assignability suite (src/test/types.tsx~L632+) pins annotation-vs-constructed identity across intrinsic tags, wrapped/class/memo/forwarded/polymorphic/attrs targets. ThedefaultPropsprecision claim is transitively pinned by those identity checks since it lives on the sharedIStyledComponentBase.
The change is microbenchmark-backed on a realistic consumer fixture (satisfying the repo's bench-the-realistic-workload mandate), and the two changesets together disclose the only observable surface difference: the deprecated propTypes field's typing is gone.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — The single new commit since the prior review (99a6d18b) closes the one API-parity gap the perf swap left behind: it re-declares defaultProps?: Partial<BaseProps> | undefined on the public PolymorphicComponent interface so the exported base type keeps the defaultProps member its ForwardRefExoticComponent base used to supply, while the deprecated propTypes typing stays removed. docs/type-performance.md and the inline types.ts comments were updated to match, and the committed budget figures (736,263 web / 810,440 augment) are unchanged.
- Restored
defaultPropson the publicPolymorphicComponent— the re-declaration is additive overNamedExoticComponent(which exposes neither member) and is shadowed on real styled components byIStyledComponentBase's narrowerdefaultProps?: (ExecutionProps & Partial<Props>), so the per-annotation walk never re-enters the declaration-site relation, matching the claimed zero delta. - Docs and comments updated coherently — the changeset and
docs/type-performance.mdnow statedefaultPropstyping behaves exactly as before, which holds both on the React 18 baseline (member restored) and React 19 (member added without conflict).
I cross-checked the load-bearing claims rather than trusting the benchmark: ForwardRefExoticComponent adds only propTypes over NamedExoticComponent under @types/react 19 (and defaultProps + propTypes under the 18 baseline), so the fix restores exactly the member the swap dropped; IStyledComponentBase (types.ts:433) extends PolymorphicComponent and redeclares defaultProps with the real ExecutionProps & Partial<Props> shape, confirming the shadowing argument; and the live budget files match the reported "unchanged" figures.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Caution
The latest commit's goal is to keep this perf swap non-breaking, but the propTypes member it re-adds references React.WeakValidationMap, a type that was removed from @types/react in v19. For React 19 consumers — fully within the supported peer range (react >= 16.8.0, no upper bound) — the published types now reference a namespace member that does not exist, producing TS2694 errors. I reproduced this directly: tsc --noEmit --project tsconfig.test-types.json against the installed @types/[email protected] fails at src/types.ts:388 with Namespace 'React' has no exported member 'WeakValidationMap'. This breaks the React 19 type surface and contradicts the changeset's claim that propTypes "behave exactly as before".
Reviewed changes — the delta since the prior review (4ac16f56, 2f8473eb):
- Reframed the PR from breaking to non-breaking by keeping
defaultProps?: Partial<BaseProps> | undefinedand re-addingpropTypes?: React.WeakValidationMap<any> | undefinedon the publicPolymorphicComponent, so no member is removed from the base type. - Rewrote
docs/type-performance.mdand the inlinetypes.tscomments to attribute the cost to per-component parameterization (not member removal) and to document why the re-declared shapes relate cheaply. - Recast the
faster-styled-component-annotationschangeset to assert no public type surface changes, changedpublic-styled-component-annotationtopatch, and re-measured the budget files (-9.9% web / -9.1% augment instantiations; ~+0.4% over dropping both members). - Added an AGENTS.md semver rule distinguishing additive (patch) from breaking (minor/major) type-only changes.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
2f8473e to
70b4cb5
Compare
There was a problem hiding this comment.
Caution
The blocking issue from the prior review is still unfixed: PolymorphicComponent re-declares propTypes?: React.WeakValidationMap<any>, but WeakValidationMap was removed from @types/react in v19. This delta is a rebase of the same content onto a newer 6.x base — no substantive change — so the break is still live.
Reviewed changes — since Pullfrog's last review at 2f8473eb, the branch was force-pushed/rebased onto base 7ce6aea4 and squashed into three commits (dffc416d perf type change, 21c21627 AGENTS.md semver rule, 70b4cb59 changeset minor→patch). Net content is unchanged from what was already reviewed:
PolymorphicComponentswaps its exotic base toReact.NamedExoticComponentand re-declaresdefaultProps?: Partial<BaseProps> | undefinedandpropTypes?: React.WeakValidationMap<any> | undefined— identical to the previously reviewed state.docs/type-performance.mdadded a section documenting the per-component parameterization cost and why the two members are re-declared in non-parameterized shapes.- AGENTS.md gains a semver rule for additive vs. breaking type-only changes; the
public-styled-component-annotationchangeset drops minor→patch.
Nothing in these commits addresses the previously flagged critical issue, so the PR still cannot merge as-is.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — since Pullfrog's last review at 70b4cb59, a single commit (8251532b) landed that resolves the blocking React 19 break:
- Fixed
propTypesfor React 19 consumers —PolymorphicComponent.propTypeschanged fromReact.WeakValidationMap<any> | undefinedtoany.WeakValidationMapwas removed from@types/react19, and the peer range isreact >= 16.8.0with no upper bound, so any reference to it published aTS2694into every React 19 consumer's build — defeating the commit's whole non-breaking goal.anyis the one spelling that resolves across the supported range (it is also exactly what@types/react19's ownForwardRefExoticComponentdeclares), stays assignable in both consumer usage directions, and remains a fixed type so the declaration-site relation still short-circuits. This is precisely the resolution the previous reviews recommended. - Docs and comments updated consistently —
docs/type-performance.mdand the inlinetypes.tscomments now explain whypropTypesmust beany, note the cross-version hazard (the type suites run only against@types/react18, so React-namespace changes need a manual 19 check), and keep the non-breaking reframing intact. - Budgets re-measured —
type-perf.budget.json(738,335 web) andtype-perf.augment.budget.json(812,680 augment) instantiations, both marginally lower than the prior figures, consistent withanybeing cheaper thanWeakValidationMap<any>.
I re-confirmed the fix at src/types.ts:390 (propTypes?: any), verified the remaining WeakValidationMap references are only in explanatory comments (not declared members), and confirmed the doc/comment stories match the shipped type. The three previously-open review threads (the TS2694 break at line 388 and the stale portability comment) are all addressed by this commit and were resolved. No remaining WeakValidationMap type references exist in the public surface.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ No critical issues — the new declaration gate is sound and load-bearing. One minor doc/precision nit inline.
Reviewed changes — the new commit since the prior approved review (8251532b) automates the "verify React-namespace changes against @types/react 19 by hand" hazard that the earlier any fix could only document:
- Added a published-declaration gate —
test:types:distruns newscripts/typeCheckDist.mjs, compiling the emitteddist/index.d.ts+dist/native/index.d.tsunderskipLibCheck: falseagainst the pinned@types/react18 and an aliased@types/react-19, and fails on any diagnostic in the package's owndist/(dependency.d.tsnoise filtered). - Wired it into the CI
buildjob afterpnpm build, added the@types/react-19/@types/react-dom-19aliased devDeps, and documented the command inAGENTS.mdanddocs/type-performance.md.
I validated the load-bearing claims directly rather than trusting the intent: the built package passes the gate on both 18 and 19, and a positive control (reintroducing propTypes?: React.WeakValidationMap<any> into dist/types.d.ts) reproduces the exact TS2694 on the 19 target with exit 1 while the 18 target stays clean — confirming the gate catches the bug that actually shipped and does not false-positive. Build (including the native DOM-isolation signature check) is green.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| // Minimum and maximum supported @types/react majors. The peer range is | ||
| // `react >= 16.8.0`; 18 is the pinned baseline the contract suite already covers, |
There was a problem hiding this comment.
The "min and max supported @types/react majors" framing overstates the lower bound. The peer range is react >= 16.8.0, so @types/react@16 and @types/react@17 are in-support consumers, but the 18 target is the pinned baseline, not the floor. A type name the library newly uses that was only introduced in @types/react 18 would ship to React 16/17 consumers as their build's TS2694, and this gate (like the contract suite) would not catch it — the exact failure mode this PR exists to prevent, just in the opposite direction. The gate is exactly right for the removed-names case (19); consider either correcting the prose to "pinned baseline (18) + max (19)" (the same claim repeats in AGENTS.md:63 and the test.yml:51-54 comment) or, if an unbounded floor matters, adding 16/17 targets.
There was a problem hiding this comment.
ℹ️ The refactor is correct and the gate stays load-bearing — one non-blocking operational consideration inline.
Reviewed changes — the single new commit since my prior review (63b2a6dc) reworks how the declaration gate resolves its max-major types:
- Dropped the
@types/react-19/@types/react-dom-19devDependency aliases (and their lockfile entries) and instead have the gate install the pinned max majors (@types/[email protected],@types/[email protected]) into a path-scoped, gitignored folder vianpm install --no-save --no-package-lock, selecting them purely throughpaths+types: ['node']and printing the resolvedversionAt(...)in the run label. Min resolves from the project's own pinned@types/react18.
This is the correct move: the aliased form I reviewed would have dropped a second copy of @types/react into node_modules/@types, and since this repo leaves types unset, TypeScript would auto-include both majors' ambient globals into every normal type-check. I re-verified the refactored gate in this environment — both targets compile clean (18.3.28 / 19.2.18), and the positive control (reintroducing propTypes?: React.WeakValidationMap<any> into dist/types.d.ts) still reproduces the exact TS2694 on the 19 target with exit 1 while 18 stays clean.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
|
||
| /** Install the max-major @types into a path-scoped folder no other tsconfig sees. */ | ||
| function isolatedMax() { | ||
| const root = join(workDir, 'max'); | ||
| if (!existsSync(join(root, 'node_modules', '@types', 'react', 'package.json'))) { | ||
| mkdirSync(root, { recursive: true }); | ||
| writeFileSync(join(root, 'package.json'), '{"private":true}\n'); | ||
| execFileSync('npm', ['install', '--no-save', '--no-package-lock', MAX.react, MAX.reactDom], { |
There was a problem hiding this comment.
The isolation is the right call, but it moves a live npm install into the build CI job at test time. GitHub Actions jobs are ephemeral, so workDir/max never survives between runs — the max-major @types (and its transitive, freshly-resolved deps like csstype, unpinned by any lockfile) is downloaded from the npm registry on every test:types:dist run, and a registry outage/rate-limit now fails the whole build job even when the code is fine. This is a reasonable tradeoff (instrumented infra like color: [react]-pinned targets and the repo's own scratch-npm i precedent), so non-blocking — but worth consciously accepting, e.g. whether a pnpm-store cache or an offline fallback is warranted before merge.
…orts PolymorphicComponent extended React.ForwardRefExoticComponent, which drags in the defaultProps/propTypes/$$typeof relation that TypeScript re-checks at every annotated declaration site. Extending React.NamedExoticComponent instead drops that inherited cost while keeping the same call signature and ref forwarding. defaultProps and propTypes are re-declared on the interface so nothing about the emitted type changes for consumers. propTypes is typed as `any` (matching React 19's own base component) rather than WeakValidationMap, which @types/react removed in v19, so the declaration compiles for both React 18 and 19 consumers. Consumer budgets drop ~10%; intrinsic-tag and union-prop annotations fall furthest.
… majors The type-contract suite only compiles against the pinned @types/react 18, so a name that exists there but was removed on a newer major (as WeakValidationMap was on 19) can ship into dist unnoticed and break every strict React 19 consumer's build. test:types:dist compiles the built .d.ts under skipLibCheck: false against the minimum and maximum supported @types/react majors, failing on any diagnostic located in the package's own dist/. The maximum major installs into a gitignored, path-scoped folder so a second @types/react never enters the repo's ambient type set; each run checks exactly one major, chosen by explicit paths, and prints the resolved version. Wired into CI after the type-perf checks.
…command An additive type change ships as a patch (it cannot break a consumer's build); a breaking type change is bumped as a breaking change even though no runtime code moved. Also documents test:types:dist so the cross-major declaration gate is discoverable.
55dc137 to
0251fa1
Compare
|
the model provider had a temporary upstream failure. The provider refused or dropped the request mid-run — nothing in your repo or your credentials is at fault. Re-trigger Pullfrog; if it keeps happening, check the provider's status page.
|

When you annotate an exported styled component with an explicit type, type-checking is now meaningfully faster. This is the pattern that packages emitting their own declaration files rely on, including any project using
isolatedDeclarations, where inference can't cross the declaration boundary and every export needs a written type.The speedup scales with how many props the underlying target has, so it lands largest exactly where these codebases feel it today: components built on intrinsic tags like
styled.divandstyled.button, and wrappers over polymorphic components whose props are a union (a button/anchor, say). On the realistic consumer fixture the type instantiation count drops ~10%; on the heaviest annotation kinds it is closer to ~40% per component. Building components and rendering them is unchanged, this is purely the cost of the explicit annotation.Nothing about the component's public type changes for your code. Props,
defaultProps,propTypes, ref forwarding, andaspolymorphism all behave exactly as before, and the publicStyledComponent<Target, Props>annotation still resolves to the exact typestyled(...)produces. It is a type-only, non-breaking change.Verified green: the full type contract suite, the web and native runtime suites, and a set of declaration-site soundness checks (a wrong prop type is rejected, a wrong ref element is rejected,
defaultPropsstays narrowed,propTypesreads and writes still compile,asstill resolves the target's props). Measured on TypeScript 5.9 and confirmed identical on the TypeScript 7 native compiler.