react-native-element-dropdown
react-native-element-dropdown copied to clipboard
incorrect type for value prop
https://github.com/hoaphantn7604/react-native-element-dropdown/blob/7542ab246dc2d57744cbd0e1bc213681e3fd7047/src/components/Dropdown/model.ts#L38
This declaration doesn't work if the value prop is of type number or some other type. It should probably be equivalent to typeof T.value I'm aware that expression can't appear here and that the fact that valueField is also a parameter prevents the use of T['value']
I also ran into this issue.
My T is { label: string, value: number }.
As a workaround I put this in a separate .d.ts file
declare module "react-native-element-dropdown" {
import { JSXElementConstructor, ReactElement } from "react";
import type { DropdownProps } from "react-native-element-dropdown/lib/typescript/components/Dropdown/model";
type NumberDropdownProps<T> = Omit<DropdownProps<T>, "value"> & {
value?: number | undefined;
};
export const Dropdown: <T>(
props: NumberDropdownProps<T>,
) => ReactElement<any, string | JSXElementConstructor<any>> | null;
}
Today I updated my workaround to this:
declare module "react-native-element-dropdown" {
import { JSXElementConstructor, ReactElement } from "react";
import type { DropdownProps } from "react-native-element-dropdown/lib/typescript/components/Dropdown/model";
type ValueDropdownProps<T> = Omit<
DropdownProps<T>,
"value" | "data" | "valueField"
> & {
data: T[];
value?: T["value"] | undefined;
valueField: "value";
};
export const Dropdown: <T>(
props: ValueDropdownProps<T>,
) => ReactElement<any, string | JSXElementConstructor<any>> | null;
}
It's less flexible than the official typings (your value field has to be named "value") but it's good enough for me for now