Skip to content

How option components type setValue under strictFunctionTypes #404

Done

Description

@jtklein-agents

Question

Under strictFunctionTypes, how do the option components type the setValue they receive?

OptionSelect's OptionSelectOptionLike declares setValue: ( value: unknown ) => void (src/app/components/OptionSelect.tsx:20); store options pass ( value: string ) => void, which is no longer assignable. That causes the prop errors at src/app/App.tsx:221, :249, :314, :503 (via InputRun, ModelRun, RaxmlRun, EditorAlignment) and src/app/AlignmentCard.tsx:249. OptionTextField (string) and OptionCheck (boolean) already name their value type.

Options to weigh:

  • A generic OptionSelectOptionLike<Value> (and matching options/value types), threaded through the prop types that embed it.
  • Method syntax (setValue( value: unknown ): void), which is bivariant and turns the check off for this member.
  • Narrow unknown to the union of values selects actually hold.

Activity

  1. added
    wayfinder:grilling
    on Nov 27, 2026
  2. jtklein-agents commented on Nov 27, 2026

    @jtklein-agents
    OwnerAuthor

    Resolution

    Facts (scratch compile under --strict): the target setValue: ( value: unknown ) => void is a function-typed property, so strictFunctionTypes rejects the store's ( value: string ) => void. Narrowing unknown to string | number | readonly string[] fails the same way. observer (mobx-react-lite overload observer<C>( c: C ): C & …) keeps a generic component's type parameter. MUI types e.target.value as Value | string (its SelectChangeEvent includes a plain input change event).

    1. Generic. OptionSelectOptionLike<Value extends string | number | readonly string[]>; value: Value, setValue: ( value: Value ) => void. OptionSelect becomes a generic observer component. Its onChange keeps a single e.target.value as Value, with a one-line comment naming MUI's change event union as the reason. Rejected: method syntax (setValue( value: unknown ): void) — compiles with no cast but turns the check off for the member, letting a number option silently receive a string (the class of bug in Part start and end setters receive strings from OptionTextField).
    2. OptionTextField and OptionCheck stay as they are: they already name string/boolean and raise no strict errors.
    3. Every embedding field names its real value type, no default type parameter: for example in ModelRun, RaxmlRun, CardAlignment's ng* fields, EditorAlignment.partition.partToAdd: numThreads/numRuns → <number>, numRepetitions/numRepetitionsNg → <number | string>, outGroup → <string[]>, the rest <string>. A string default would quietly mis-type the number and array options.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

wayfinder:grilling

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions