Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incorrect type for value prop #286

Open
ChrisChiasson opened this issue Jul 10, 2024 · 2 comments
Open

incorrect type for value prop #286

ChrisChiasson opened this issue Jul 10, 2024 · 2 comments

Comments

@ChrisChiasson
Copy link

ChrisChiasson commented Jul 10, 2024

value?: T | string | null | undefined;

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']

@Tobbe
Copy link

Tobbe commented Jan 9, 2025

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;
}

@Tobbe
Copy link

Tobbe commented Jan 10, 2025

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

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

No branches or pull requests

2 participants