Skip to content

fix: add types field to package.json#518

Merged
erikras merged 5 commits into
mainfrom
fix/add-types-field
Feb 11, 2026
Merged

fix: add types field to package.json#518
erikras merged 5 commits into
mainfrom
fix/add-types-field

Conversation

@erikras-gilfoyle-agent

@erikras-gilfoyle-agent erikras-gilfoyle-agent commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

TypeScript types are generated and published to dist/index.d.ts but package.json has "types": null, preventing TypeScript from finding them.

This adds the missing types field to package.json so TypeScript can locate the type definitions.

Summary by CodeRabbit

  • Documentation

    • Added a TypeScript types entry in package metadata to improve IDE hints and TypeScript tooling support.
  • Refactor

    • Relaxed internal state type constraints to allow optional fields, improving flexibility and robustness of field handling.

TypeScript types are generated and published to dist/index.d.ts but
package.json has "types": null, preventing TypeScript from finding them.
@coderabbitai

coderabbitai Bot commented Feb 11, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Added TypeScript typings entry to package.json and made InternalFieldState.instanceId optional; FinalForm now initializes instanceId (undefined) when registering fields to support async validation supersession checks.

Changes

Cohort / File(s) Summary
Package Metadata
package.json
Added top-level types field set to dist/index.d.ts.
Type Definitions
src/types.ts
Changed InternalFieldState.instanceId to be optional (`number
Form Runtime
src/FinalForm.ts
Initialize instanceId as undefined when registering fields and use it to track/supersede asynchronous field validations.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant User
participant Form as FinalForm
participant Field
participant Validator as AsyncValidator
User->>Form: register field
Form->>Field: create InternalFieldState (instanceId = undefined)
User->>Field: trigger validation
Field->>Validator: start async validation (attach instanceId)
Validator-->>Field: async result (with instanceId)
Field->>Form: deliver result
alt instanceId matches current
Form->>Field: accept validation result
else instanceId differs (stale)
Form->>Field: ignore result
end

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • erikras-richard-agent
  • erikras

Poem

🐰 I hopped through code with careful stride,
instanceId tucked in, now optional inside,
Types declared where dist indexes lie,
Async checks glance and older ones fly,
A tiny hop, a steadier tide. 🥕

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'fix: add types field to package.json' directly describes the main change in the PR. However, the changeset also includes significant modifications to src/types.ts and src/FinalForm.ts related to adding and using instanceId, which are not reflected in the title. The title is partially accurate but incomplete. Consider whether the title should be broadened to reflect all changes, such as 'fix: add types field and instanceId tracking for async validations', or if the scope should be narrowed to focus on the primary objective.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/add-types-field

No actionable comments were generated in the recent review. 🎉


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

coderabbitai[bot]
coderabbitai Bot previously approved these changes Feb 11, 2026
Fixes TypeScript error where instanceId property was missing from the
initial field state object literal. The property is required by
InternalFieldState interface but was only being assigned after creation,
causing type errors.

This fixes CI failures in the Bundle Size Check job.
erikras
erikras previously approved these changes Feb 11, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 `@src/FinalForm.ts`:
- Line 914: The registration object currently sets instanceId: 0 which prevents
the nullish coalescing in the assignment (field.instanceId ??
++nextFieldInstanceId) from generating unique IDs; remove the explicit
instanceId property from the object literal created in the registration path
(the object used when registering fields) so that field.instanceId is undefined
and the expression using nextFieldInstanceId (referenced as nextFieldInstanceId
and field.instanceId in the code) can correctly assign incremented unique
instance IDs and restore the async validation staleness check that compares
currentField.instanceId === fieldInstanceId.

Comment thread src/FinalForm.ts Outdated
CodeRabbit correctly identified that setting instanceId: 0 prevents the
nullish coalescing operator from working. Since 0 is not null/undefined,
field.instanceId ?? ++nextFieldInstanceId will always use 0 instead of
generating unique IDs, breaking async validation staleness checks.

Removing the explicit initialization allows the assignment on line 930 to
properly generate unique instance IDs.
coderabbitai[bot]
coderabbitai Bot previously approved these changes Feb 11, 2026
TypeScript requires all interface properties to be present in object literals.
Since instanceId is assigned via nullish coalescing after object creation,
it needs to be optional in the interface definition.

This allows the registration code to omit instanceId from the initial object,
letting the assignment (field.instanceId ?? ++nextFieldInstanceId) properly
generate unique IDs.
coderabbitai[bot]
coderabbitai Bot previously approved these changes Feb 11, 2026
TypeScript complains about accessing instanceId on the union type because
the anonymous object literal doesn't have the property. Setting it to
undefined (rather than omitting it) satisfies TypeScript while still allowing
the nullish coalescing operator to work correctly.
@erikras
erikras merged commit 2160f8f into main Feb 11, 2026
5 checks passed
@erikras
erikras deleted the fix/add-types-field branch February 11, 2026 07:54
@erikras-richard-agent

Copy link
Copy Markdown
Contributor

Published in v5.0.1

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