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

feat: make typings for customInput generic #577

Merged
merged 1 commit into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions typings/number_format.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ declare module 'react-number-format' {
data: any;
}

export interface NumberFormatPropsBase extends InputAttributes {
export type NumberFormatPropsBase<T> = {
thousandSeparator?: boolean | string;
decimalSeparator?: string;
thousandsGroupStyle?: 'thousand' | 'lakh' | 'wan';
Expand All @@ -38,7 +38,7 @@ declare module 'react-number-format' {
value?: number | string | null;
defaultValue?: number | string;
isNumericString?: boolean;
customInput?: React.ComponentType<any>;
customInput?: React.ComponentType<T>;
allowNegative?: boolean;
allowEmptyFormatting?: boolean;
allowLeadingZeros?: boolean;
Expand Down Expand Up @@ -70,13 +70,8 @@ declare module 'react-number-format' {
];
}

// The index signature allows any prop to be passed in, such as if wanting to send props
// to a customInput. We export this as a separate interface to allow client authors to
// choose the stricter typing of NumberFormatPropsBase if desired.
export interface NumberFormatProps extends NumberFormatPropsBase {
[key: string]: any;
}
export type NumberFormatProps<T> = NumberFormatPropsBase<T> & Omit<T, keyof NumberFormatPropsBase<unknown> | 'ref'>

class NumberFormat extends React.Component<NumberFormatProps, any> {}
class NumberFormat<T = InputAttributes> extends React.Component<NumberFormatProps<T>, any> {}
export default NumberFormat;
}
3 changes: 2 additions & 1 deletion typings/number_format.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import { default as NumberFormat } from 'react-number-format';

<NumberFormat value="" />;
<NumberFormat type="tel" />;
<NumberFormat type="tel" readOnly={false} />;
<NumberFormat type="tel" readOnly={false} size={1} />;
<NumberFormat customInput={(props: { size: "small" | "large" }) => <></>} type="tel" size="small" />;