// Experimental TypeScript typings. // https://gitlab.com/catamphetamine/input-format/-/issues/1 import type { InputHTMLAttributes, Ref, KeyboardEvent, ChangeEvent } from 'react'; import { ParseFunction, FormatFunction } from '../index.d'; type Props = InputComponentProps & { parse: ParseFunction; format: FormatFunction; onChange?(value?: string): void; onKeyDown?(value?: string): void; }; type ControlledProps = Props & { value?: string; controlled?: true; }; type UncontrolledProps = Props & { defaultValue?: string; controlled: false; }; type CommonOutputProps = { // https://miroslavpetrik.medium.com/how-to-type-the-ref-prop-in-typescript-react-c0fffe939288 ref: Ref; onChange(event: ChangeEvent): void; onKeyDown(event: KeyboardEvent): void; }; export function useInput>(props: ControlledProps): InputComponentProps & CommonOutputProps & { value: string; }; export function useInput>(props: UncontrolledProps): InputComponentProps & CommonOutputProps & { defaultValue?: string; };