yury-dymov / react-autocomplete-input

Autocomplete input field for React
https://yury-dymov.github.io/react-autocomplete-input/
MIT License
199 stars 65 forks source link

missing declaration file (TS7016) #101

Closed HannesPaa closed 1 year ago

HannesPaa commented 1 year ago

It would be great to have TypeScript Support.

HannesPaa commented 1 year ago

Maybe somthing like this.

declare module "react-autocomplete-input" {
  import React, { ComponentType, KeyboardEvent, ReactNode } from "react";

  type AutocompleteTextFieldPropsGeneral = {
    Component?: string | ComponentType<any>;
    defaultValue?: string;
    disabled?: boolean;
    maxOptions?: number;
    onBlur?: () => void;
    onChange?: (value: string) => void;
    onKeyDown?: (event: KeyboardEvent) => void;
    onRequestOptions?: (value: string) => void;
    onSelect?: (value: string) => void;
    changeOnSelect?: (trigger: string, slug: string) => string;
    regex?: string;
    matchAny?: boolean;
    minChars?: number;
    requestOnlyIfNoOptions?: boolean;
    spaceRemovers?: string[];
    spacer?: string;
    value?: string | null;
    offsetX?: number;
    offsetY?: number;
    passThroughEnter?: boolean;
  };

  export type AutocompleteTextFieldProps =
    | ({
        options: string[];
        trigger: string;
      } & AutocompleteTextFieldPropsGeneral)
    | ({
        options: { [key: string]: string[] };
        trigger: string[];
      } & AutocompleteTextFieldPropsGeneral);

  /**
   * AutocompleteTextField
   * @param options - An array of strings or an object with keys as triggers and values as options
   * @param trigger - If options has keys, this should be an array of triggers
   */
  export default class AutocompleteTextField extends React.Component<AutocompleteTextFieldProps> {}
}
rsbmkJ commented 1 year ago

I need types D;

yury-dymov commented 1 year ago

Closed via https://github.com/yury-dymov/react-autocomplete-input/pull/103