feat: report type errors for disabled features #56
Open
KevinVandywants to merge 1 commit into
main fromkevin/feature-types·opened Makes TypeScript report an error where app code uses a feature that redact() turns off.
src/features/suspense.tsx(6,6): error TS2741: Property ''Redact: <Suspense> requires the `suspense` feature. Set `features.suspense: true` in redact().'' is missing in type '{ children: Element; fallback: Element; }' but required in type 'SuspenseProps'.
redact()writessrc/redact.gen.d.tsfrom the resolved feature flags. The file has one/// <reference types="@tanstack/redact/disabled/<feature>" />line per disabled feature. It is rewritten only when its content changes. The newdtsoption sets another path or turns the file off. Withoutsrc/, the default file is skipped. A custom path whose directory is missing logs a warning.packages/redact/disabled/*.d.tsmerge into@types/reactand@types/react-dom. Declaration merging can only add, so each file makes the existing API unusable:<Activity>,<Suspense>, context providers, andforwardRef()get a requiredneverprop. The prop name is the error message.lazy(),createPortal(), andhydrateRoot()get an overload that takes priority and returns an unusable type. The overload is also marked@deprecated.- Class lifecycles other than
render,setState, andcomponentWillUnmountget conflicting overloads. A class that uses none of them still satisfiesComponentType. memo()andaddTransitionType()are only marked@deprecated, because turning them off changes performance or animation rather than behavior.fragmentRefshas no type check.
@types/reactand@types/react-domare optional peer dependencies, so pnpm links the same copy the app uses.tests/feature-types.test.tstype-checks a fixture against@types/react19.3 withskipLibCheck: false. Errors appear only on marked lines, enabled features add none, and the language service reports the expected deprecations.examples/feature-typesturns off every feature and then uses each one.pnpm typecheckthere reports 12 errors.ssr-demosetsdts: falsebecause its tsconfig mapsreactto Redact's source.
Notes#
The file is written by default, so every Vite project with a src/ folder gets one. With the full preset it only references viewTransitions. We may want to make it opt-in before release. Only the app's own source is checked. Compiled dependencies are not.
- 1
Important
Draft PR not reviewed#
Draft PRs are not automatically reviewed by default.
- Trigger a manual review
To automatically review draft PRs, update your CodeRabbit configuration:
reviews: auto_review: drafts: true- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment `@coderabbitai help` to get the list of available commands.Review the following changes in direct dependencies. Learn more about Socket for GitHub.
Diff Package Supply Chain
SecurityVulnerability Quality Maintenance License @types/react-dom@19.3.0 @types/react@19.3.0
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: da80583e8dae080af530de0ff50379e5270150e7
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