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

Typescript error for Icon #478

Closed
kickbk opened this issue Apr 21, 2022 · 8 comments
Closed

Typescript error for Icon #478

kickbk opened this issue Apr 21, 2022 · 8 comments

Comments

@kickbk
Copy link

kickbk commented Apr 21, 2022

Getting

function(): JSX.Element
No overload matches this call.
  Overload 1 of 2, '(props: PickerSelectProps | Readonly<PickerSelectProps>): Picker', gave the following error.
    Type '() => JSX.Element' is not assignable to type 'ReactNode'.
  Overload 2 of 2, '(props: PickerSelectProps, context: any): Picker', gave the following error.
    Type '() => JSX.Element' is not assignable to type 'ReactNode'.ts(2769)
[SelectTime.tsx(116, 18): ]()Did you mean to call this expression?

when using like so:

<RNPickerSelect
  ...
  Icon={() => {
    return <Ionicons ... />;
  }}
/>

Any recommendations?

@samuel-anderson
Copy link

Any update on this? I'm getting the same issue.

@nicolaswbam
Copy link

nicolaswbam commented Jul 27, 2022

I had the same issue, fixed it by updating typescript to version 4.7.3 and @types/react to 17.0.43 .

The type of Icon is React.ReactNode, but it is rendered as <Icon/> which is a component.

However you should not create an inline component. Instead, you can create a component in the same file as

const CustomPickerIcon = () => {
  return <MyIcon />;
}; 
...
...
...
 <RNPickerSelect
        ...
        Icon={CustomPickerIcon}
      />

@WahidN
Copy link

WahidN commented Oct 19, 2022

@nicolaswbam that still gives me the TS error

@Yupeng-li
Copy link

@WahidN It's a bug of the type mentioned here #488

@KhimGurung
Copy link

KhimGurung commented Jan 24, 2023

Passing a function or component is working in my case but why it is failing my test.

  const renderIcon = () => {
    return Platform.OS === "android" ? null : (
      <Icon name="caretdown"
      />
    );
  };

    <PickerSelect
      Icon={renderIcon()}
      {...props}
    />

I am getting:

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.

But if I do like bellow, the test passes but shows error. Weird part is I can run my application.

    <PickerSelect
      Icon={() => {
        return Platform.OS === "android" ? null : (
          <Ico name="caretdown" />
        );
      }}
      {...props}
    />

I can update Icon type from React.ReactNode to React.FC and everything works fine but I dont want to change node_modules file.

@lfkwtz
Copy link
Collaborator

lfkwtz commented Nov 27, 2023

anyone want to open a pr for this?

noterB added a commit to noterB/react-native-picker-select that referenced this issue Nov 30, 2023
@bbun0639
Copy link

bbun0639 commented Dec 3, 2023

I can update Icon type from React.ReactNode to React.FC and everything works fine but I dont want to change node_modules file.

It's work fine.

@lfkwtz
Copy link
Collaborator

lfkwtz commented Jan 10, 2024

can some of y'all review this mr?

#529

@lfkwtz lfkwtz closed this as completed Jan 25, 2024
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

8 participants