react-native-picker-select icon indicating copy to clipboard operation
react-native-picker-select copied to clipboard

Typescript error for Icon

Open kickbk opened this issue 2 years ago • 2 comments

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?

kickbk avatar Apr 21 '22 17:04 kickbk

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

samuel-anderson avatar Jun 30 '22 12:06 samuel-anderson

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

nicolaswbam avatar Jul 27 '22 08:07 nicolaswbam

@nicolaswbam that still gives me the TS error

WahidN avatar Oct 19 '22 14:10 WahidN

@WahidN It's a bug of the type mentioned here https://github.com/lawnstarter/react-native-picker-select/issues/488

Yupeng-li avatar Jan 06 '23 16:01 Yupeng-li

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.

KhimGurung avatar Jan 24 '23 10:01 KhimGurung

anyone want to open a pr for this?

lfkwtz avatar Nov 27 '23 15:11 lfkwtz

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.

bbun0639 avatar Dec 03 '23 06:12 bbun0639

can some of y'all review this mr?

#529

lfkwtz avatar Jan 10 '24 21:01 lfkwtz