fix: add types field to package.json#518
Conversation
TypeScript types are generated and published to dist/index.d.ts but package.json has "types": null, preventing TypeScript from finding them.
📝 WalkthroughWalkthroughAdded TypeScript typings entry to package.json and made Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 Comment |
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.
There was a problem hiding this comment.
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.
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.
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.
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.
|
Published in |
TypeScript types are generated and published to
dist/index.d.tsbut package.json has"types": null, preventing TypeScript from finding them.This adds the missing
typesfield to package.json so TypeScript can locate the type definitions.Summary by CodeRabbit
Documentation
Refactor