Update react-tagsinput Type Mappings to use Generics instead of <any>… (#43586)

* Update react-tagsinput Type Mappings to use Generics instead of <any> for tag types.

* Update react-tagsinput Generic Support to better handle backward compatibility. Added support to `keyof` Generic type for tagDisplayProp.
This commit is contained in:
jthornca
2020-04-03 10:15:43 -07:00
committed by GitHub
parent ca88c61edc
commit 8e264ca252
+8 -10
View File
@@ -10,9 +10,7 @@ import * as React from "react";
export as namespace ReactTagsInput;
export = TagsInput;
type Tag = any;
declare class TagsInput extends React.Component<TagsInput.ReactTagsInputProps> {
declare class TagsInput<Tag = any> extends React.Component<TagsInput.ReactTagsInputProps<Tag>> {
accept(): any;
addTag(tag: Tag): any;
blur(): void;
@@ -22,10 +20,10 @@ declare class TagsInput extends React.Component<TagsInput.ReactTagsInputProps> {
declare namespace TagsInput {
interface InputProps {
readonly [prop: string]: any;
readonly [prop: string]: any;
}
interface RenderInputProps extends InputProps {
interface RenderInputProps<Tag = any> extends InputProps {
readonly addTag: (tag: Tag) => void;
readonly onChange: (e: React.ChangeEvent<{ readonly value: string }>) => void;
readonly ref: (r: any) => void; // parameter is either a DOM element or a mounted React component
@@ -36,7 +34,7 @@ declare namespace TagsInput {
readonly [prop: string]: any;
}
interface RenderTagProps extends TagProps {
interface RenderTagProps<Tag = any> extends TagProps {
readonly disabled: boolean;
readonly getTagDisplayValue: (tag: Tag) => string;
readonly onRemove: (tagIndex: number) => void;
@@ -45,7 +43,7 @@ declare namespace TagsInput {
type RenderLayout = (tagElements: React.ReactElement[], inputElement: React.ReactElement) => React.ReactChild;
interface ReactTagsInputProps extends React.Props<TagsInput> {
interface ReactTagsInputProps<Tag = any> extends React.Props<TagsInput<Tag>> {
value: Tag[];
onChange: (tags: Tag[], changed: Tag[], changedIndexes: number[]) => void;
onChangeInput?: (value: string) => void;
@@ -65,9 +63,9 @@ declare namespace TagsInput {
focusedClassName?: string;
tagProps?: TagProps;
inputProps?: InputProps;
tagDisplayProp?: string | null;
renderTag?: (props: RenderTagProps) => React.ReactNode;
renderInput?: (props: RenderInputProps) => React.ReactNode;
tagDisplayProp?: keyof Tag | string | null;
renderTag?: (props: RenderTagProps<Tag>) => React.ReactNode;
renderInput?: (props: RenderInputProps<Tag>) => React.ReactNode;
renderLayout?: RenderLayout;
preventSubmit?: boolean;
}