wix / react-native-ui-lib

UI Components Library for React Native
https://wix.github.io/react-native-ui-lib/
MIT License
6.44k stars 706 forks source link

NumberInput requires all props from TextFieldProps (Type error) #2515

Closed janoseross closed 1 year ago

janoseross commented 1 year ago

Description

NumberInput component requires all of the TextFieldProps in order to use.

Related to

Steps to reproduce

  1. Import and use NumberInput component with preferred props. (I used initialNumber, placeholder and onChangeNumber - important to understand the error message below)
  2. See TS error

Expected behavior

The component can be used without any Types.

Actual behavior

The component is marked incorrect, the following Type error appears: Type '{ initialNumber: any; placeholder: string; onChangeNumber: (value: any) => void; }' is missing the following properties from type 'Pick<any, "margin" | "marginL" | "marginT" | "marginR" | "marginB" | "marginH" | "marginV" | "padding" | "paddingL" | "paddingT" | "paddingR" | "paddingB" | "paddingH" | "paddingV" | ... 391 more ... | "trailingTextStyle">': margin, marginL, marginT, marginR, and 398 more.ts(2740)

More Info

In order to fix the problem it is needed to use app the 400+ props mentioned above (I assume they are the props of TextFieldProps)

The source of the problem may be here, at the type definition: https://github.com/wix/react-native-ui-lib/blob/master/src/components/numberInput/index.tsx#L12

This is only a type issue, by passing @ts-ignore the component works properly.

Code snippet

<NumberInput
  initialNumber={value}
  placeholder={'Some placeholder...'}
  onChangeNumber={(value) => onChangeNumber(value)} 
/>

Screenshots/Video

image

Environment

Affected platforms

adids1221 commented 1 year ago

Hi Janos, What is the TypeScript version you're using?

janoseross commented 1 year ago

Hey @adids1221, my version is 4.9.5

minemos commented 1 year ago

Picker Component also requires all props.

minemos commented 1 year ago

Fix [components]/index.d.ts

  1. Add this type
type Partial<T> = {
    [P in keyof T]?: T[P];
};
  1. Change Pick type to Partial

For example

declare const Picker: React.ForwardRefExoticComponent<(Pick<import("./types").PickerPropsWithSingle, .....

This type must to be

declare const Picker: React.ForwardRefExoticComponent<(Partial<import("./types").PickerPropsWithSingle, .....
minemos commented 1 year ago

NumberInput too.

M-i-k-e-l commented 1 year ago

Hi @janoseross and @minemos,

It is a little weird, I am not sure why but it seems that the transpilation from typescript to javascript changes Omit to Pick. It also seems to affect only release versions (our snapshots are ok, that's why we did not see it ourselves). We are still looking at it, but no solution yet.

M-i-k-e-l commented 1 year ago

Hi @janoseross and @minemos, I've just tried to re-install our latest version (7.4) and it looks like the issue is resolved; I do not know why, so hopefully it'll not come back later... Could you please verify and if it's working for you, please close this ticket 🙏

janoseross commented 1 year ago

Indeed, the issue has been resolved. Thank you @M-i-k-e-l for your hard work!

adamzolyak commented 7 months ago

Curious if https://github.com/wix/react-native-ui-lib/issues/2933 seems similar to this issue? Could help me figure out where to dig in.