Skip to content
Source
Sign inSign up
TanStack/redact

feat: report type errors for disabled features #56

OpenKevinVandywants to merge 1 commit intomain fromkevin/feature-typesopened

KevinVandycommented

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() writes src/redact.gen.d.ts from 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 new dts option sets another path or turns the file off. Without src/, the default file is skipped. A custom path whose directory is missing logs a warning.
  • packages/redact/disabled/*.d.ts merge into @types/react and @types/react-dom. Declaration merging can only add, so each file makes the existing API unusable:
    • <Activity>, <Suspense>, context providers, and forwardRef() get a required never prop. The prop name is the error message.
    • lazy(), createPortal(), and hydrateRoot() get an overload that takes priority and returns an unusable type. The overload is also marked @deprecated.
    • Class lifecycles other than render, setState, and componentWillUnmount get conflicting overloads. A class that uses none of them still satisfies ComponentType.
    • memo() and addTransitionType() are only marked @deprecated, because turning them off changes performance or animation rather than behavior. fragmentRefs has no type check.
  • @types/react and @types/react-dom are optional peer dependencies, so pnpm links the same copy the app uses.
  • tests/feature-types.test.ts type-checks a fixture against @types/react 19.3 with skipLibCheck: false. Errors appear only on marked lines, enabled features add none, and the language service reports the expected deprecations.
  • examples/feature-types turns off every feature and then uses each one. pnpm typecheck there reports 12 errors. ssr-demo sets dts: false because its tsconfig maps react to 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. 🦋 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
      NameType
      @tanstack/redactMinor

      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

    2. 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.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    3. Review the following changes in direct dependencies. Learn more about Socket for GitHub.

      Diff Package Supply Chain
      Security
      Vulnerability Quality Maintenance License
      Added@​types/​react-dom@​19.3.01001007587100
      Added@​types/​react@​19.3.01001007990100

      View full report

Sign in to join this conversation.