Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 7, 2025

Problem

The TypeScript definitions in src/index.d.ts had incorrect function types that provided no type safety or IntelliSense support. All callback functions were defined as (...args: unknown[]): unknown;, which meant:

  • ❌ No autocomplete in IDEs
  • ❌ No type checking for arguments or return values
  • ❌ No documentation hints
  • ❌ Developers had to guess the correct parameter types

For example, onChange was defined as:

onChange?(...args: unknown[]): unknown;

This provided no information about what argument the callback receives or what it should return.

Solution

Updated all function type definitions with proper TypeScript types based on the actual implementation:

onChange

// Before
onChange?(...args: unknown[]): unknown;

// After
onChange?: (value: number | null) => void | false | number;

Now properly typed to receive the new spinner value (number or null when emptied) and can return void, false to cancel the change, or a number to override the value.

Event Handlers (onFocus, onBlur, onKeyPress)

// Before
onFocus?(...args: unknown[]): unknown;

// After
onFocus?: (e: NativeSyntheticEvent<TextInputFocusEventData>) => void;

Now use proper React Native event types for TextInput focus, blur, and key press events.

Value Callbacks (onMin, onMax, onIncrease, onDecrease, onSubmit, onLongPress)

// Before
onMin?(...args: unknown[]): unknown;

// After
onMin?: (value: number) => void;

All value callbacks now properly typed to receive a single number parameter representing the relevant value.

formatter

// Before
formatter?(...args: unknown[]): unknown;

// After
formatter?: (value: number) => string;

Now clearly shows it takes a number and must return a formatted string.

Benefits

Type Safety: TypeScript now properly validates argument and return types at compile time
IntelliSense: IDEs provide accurate autocomplete and parameter hints
Self-Documenting: Function signatures clearly show expected types
Error Prevention: Catches type mismatches before runtime
No Breaking Changes: Existing JavaScript code continues to work without modifications

Example Usage

With these changes, developers now get full type checking and autocomplete:

<InputSpinner
  value={10}
  onChange={(value) => {
    // value is typed as: number | null
    // IDE provides autocomplete for number methods
    console.log(value?.toFixed(2));
  }}
  onMin={(value) => {
    // value is typed as: number
    console.log("Min reached:", value);
  }}
  formatter={(value) => {
    // TypeScript enforces string return type
    return `$${value.toFixed(2)}`; // ✅ Correct
  }}
/>

Fixes the issue where TypeScript users had no type information for callback functions.

Original prompt

This section details on the original issue you should resolve

<issue_title>Bug: incorrect TS function types</issue_title>
<issue_description>- The types of the functions in index.d.ts are wrong

  • None of them provide any types, and look like (...args: unknown[]): unknown;
  • This is unhelpful since the types of arguments and return types aren't defined, so doesn't help enforce strict typing or tell library users which types to provide in arguments to functions or expect to return from them
  • For example, onChange is defined as: onChange?(...args: unknown[]): unknown;
  • onChange should be defined as: onChange?: (newValue: string | number | undefined) => void;</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #104

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: marcocesarato <36447518+marcocesarato@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Fix incorrect TypeScript function types in index.d.ts Fix incorrect TypeScript function types in index.d.ts Oct 7, 2025
@Copilot Copilot AI requested a review from marcocesarato October 7, 2025 21:57
Copilot finished work on behalf of marcocesarato October 7, 2025 21:57
@marcocesarato marcocesarato marked this pull request as ready for review October 8, 2025 07:28
@marcocesarato marcocesarato merged commit a151c2d into master Oct 8, 2025
1 of 3 checks passed
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.

Bug: incorrect TS function types

2 participants