Skip to content

fix: type SelectField onSelect and onDeselect by the selected option value - #344

Open
spawnia wants to merge 3 commits into
masterfrom
select-field-handlers-by-option-value
Open

spawnia wants to merge 3 commits into
masterfrom
select-field-handlers-by-option-value

Conversation

@spawnia

@spawnia spawnia commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

SelectField typed onSelect and onDeselect by the field value.
When the field path runs through a nullable parent, that value is Array<string> | null, so handlers received string | null and consumers had to assert, although a select callback only ever receives an option's value.

Both handlers now receive the element type of the non-null field value, string in the example.
value and onChange keep the field type.
Handlers that accept wider types, such as string | null, still compile.

For agents 🤖: ready for review, nothing pending

Only src/Fields/SelectField.tsx changed: onSelect/onDeselect are omitted from SelectProps and redeclared as SelectHandler<SelectedValue<TFieldValue>, TOption>.
yarn typecheck and eslint on the file pass.
A temporary usage with a nullable parent confirmed (v: string) => … compiles after the change and failed before.
The handler type derives from the field value rather than TOption['value'], because the default option value type includes number | null, which would break existing string handlers.

🤖 Generated with Claude Code

…value

A select callback only receives an option's value, never the null of an
empty field. Typing the handlers from the field value forced consumers to
assert whenever the field path ran through a nullable parent. Handlers now
receive the element type of the non-null field value; value and onChange
keep the field type.

🤖 Generated with Claude Code

Copilot AI 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.

🟡 Changes recommended

The select callback typing incorrectly retains string[] for nullable scalar-or-array fields, rejecting valid string-only onSelect and onDeselect handlers.

1 open issue
What changed in this PR

This PR refines SelectField callback types so selection handlers use an individual selected value rather than the nullable field value.

Changes:

  • Adds SelectedValue to derive callback value types.
  • Redeclares onSelect and onDeselect while preserving the field types for value and onChange.
File Description
src/​Fields/​SelectField.tsx Introduces selected-value typing for selection and deselection callbacks.

Review effort: Balanced

Comment thread src/Fields/SelectField.tsx Resolved
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 21.1.1-alpha.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 21.1.1-alpha.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@spawnia
spawnia requested a review from mic-web November 9, 2026 16:21

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants