Skip to content

expose TS definitions#42

Open
iamdey wants to merge 2 commits intofinal-form:masterfrom
iamdey:expose_ts_def
Open

expose TS definitions#42
iamdey wants to merge 2 commits intofinal-form:masterfrom
iamdey:expose_ts_def

Conversation

@iamdey
Copy link

@iamdey iamdey commented Feb 4, 2026

The type definitions exposition have not been included during TS migration. This produces defintions at build time the same way as other final-form libs especially react-final-form-arrays.

Currently the only TS type available is @types/final-form-focus which is not compatible anymore with latest releases of final-form:

> npx tsc -p ./tsconfig.json --noEmit

node_modules/@types/final-form-focus/index.d.ts:16:26 - error TS2344: Type 'InitialFormValues' does not satisfy the constraint 'Partial<FormValues>'.

16 ): Decorator<FormValues, InitialFormValues>;
                            ~~~~~~~~~~~~~~~~~

  node_modules/@types/final-form-focus/index.d.ts:13:62
    13 export default function createDecorator<FormValues = object, InitialFormValues = object>(
                                                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~
    This type parameter might need an `extends Partial<FormValues>` constraint.

I can't prove this PR works, I've tested locally with success by installing it:

npm i  --no-save --install-links <path-to-fork>/final-form-focus

Summary by CodeRabbit

  • Chores
    • Build tooling updated to generate and publish TypeScript declaration files, improving IDE support and type safety.
    • Package now declares a typings entry so published packages include TypeScript definitions.
    • Public exports expanded to include type-only exports, ensuring TypeScript consumers have access to full type information.

configure rollup the same way as is 'react-final-form-arrays'
@iamdey iamdey requested a review from erikras as a code owner February 4, 2026 14:03
@coderabbitai
Copy link

coderabbitai bot commented Feb 4, 2026

📝 Walkthrough

Walkthrough

Adds TypeScript declaration generation to the build: Rollup is configured with the TypeScript plugin and a build tsconfig that emits declarations; package.json gains a typings entry and devDependency; src/index.ts re-exports ./types.

Changes

Cohort / File(s) Summary
Build configuration
package.json, rollup.config.js, tsconfig.json, tsconfig.build.json
Adds typings field to package.json and @rollup/plugin-typescript devDependency; wires @rollup/plugin-typescript into Rollup with tsconfig.build.json (emits declarations and declaration maps); sets declarationDir in tsconfig.json and adds a build-specific tsconfig that excludes tests.
Public exports
src/index.ts
Adds export * from './types' to include type exports in the package's public API.

Sequence Diagram(s)

sequenceDiagram
  participant Dev as Developer/CI
  participant Rollup as Rollup (build)
  participant TS as TypeScript compiler
  participant Dist as dist output (files)

  Dev->>Rollup: run build
  Rollup->>TS: invoke `@rollup/plugin-typescript` with tsconfig.build.json (declaration, declarationMap)
  TS-->>Rollup: emit JS + `.d.ts` and `.d.ts.map` into declarationDir (`dist`)
  Rollup->>Dist: write bundled JS and forward type files
  Dev->>package.json: package.json.typings -> `dist/index.d.ts`
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰
I hopped through configs, tidy and spry,
Rollup and TS made types multiply,
Dist filled with declarations bright,
Now packages wear their typings right,
A little rabbit nods, delight. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'expose TS definitions' directly and clearly describes the main change: adding and exposing TypeScript type definitions (.d.ts files) to the package.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@tsconfig.build.json`:
- Around line 8-10: Update the tsconfig.build.json exclude array to also omit
test-only files so declaration files aren't emitted for tests; specifically add
patterns such as "./src/**/*.test.tsx", "./src/**/*.test.ts", and a directory
pattern like "**/__tests__/**" (or similar) to the existing exclude list in
tsconfig.build.json so future TSX tests or __tests__ folders are ignored by the
declaration emit process.

Copy link

@erikras-richard-agent erikras-richard-agent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work! 👏 This follows the same pattern as your fix for react-final-form-arrays (#186).

What this fixes:

  • Generates TypeScript definitions at build time (currently missing)
  • Replaces outdated/incompatible @types/final-form-focus
  • Adds proper typings field to package.json
  • Uses tsconfig.build.json to control declaration generation

Code review:
✅ Correct use of @rollup/plugin-typescript
✅ tsconfig.build.json properly extends base config and excludes tests
✅ Types exported from index.ts via export * from './types'
✅ CodeRabbit approved
✅ Follows Final Form ecosystem conventions

This is part of the broader effort to fix TypeScript type publishing across all Final Form repos. Great contribution!

@erikras - Recommend merge. This fixes a gap in the TypeScript migration.

erikras
erikras previously approved these changes Feb 6, 2026
@erikras-richard-agent erikras-richard-agent dismissed stale reviews from erikras and themself via 8b2014a February 6, 2026 18:03
@erikras-richard-agent
Copy link

✅ CodeRabbit feedback addressed

Updated tsconfig.build.json to exclude additional test file patterns:

"exclude": [
  "./src/**/*.test.ts",
  "./src/**/*.test.tsx",      // Added: TSX test files
  "**/__tests__/**"             // Added: Test directories
]

This ensures that declaration files (.d.ts) are not generated for:

  • TypeScript test files (.test.ts)
  • React/JSX test files (.test.tsx)
  • Files in __tests__ directories

Ready for merge! 🎉

Sign up for free to 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.

3 participants