From 1c601f58e42b3418fd1962c46678587e4cf06b95 Mon Sep 17 00:00:00 2001 From: Connor Bryan Date: Thu, 12 Jul 2018 13:04:22 -0500 Subject: [PATCH] Clean up typing and formatting --- common/components/AddressField.tsx | 2 +- .../AddressFieldFactory/AddressFieldDropdown.tsx | 14 +++++++++++++- .../AddressFieldFactory/AddressFieldFactory.tsx | 4 ++-- .../AddressFieldFactory/AddressInputFactory.tsx | 3 +-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/common/components/AddressField.tsx b/common/components/AddressField.tsx index 98be45de..20d6d08f 100644 --- a/common/components/AddressField.tsx +++ b/common/components/AddressField.tsx @@ -18,7 +18,7 @@ interface OwnProps { placeholder?: string; value?: string; dropdownThreshold?: number; - onChangeOverride?: (ev: React.FormEvent) => void; + onChangeOverride?(ev: React.FormEvent): void; } interface StateProps { diff --git a/common/components/AddressFieldFactory/AddressFieldDropdown.tsx b/common/components/AddressFieldFactory/AddressFieldDropdown.tsx index be02281d..258e19d6 100644 --- a/common/components/AddressFieldFactory/AddressFieldDropdown.tsx +++ b/common/components/AddressFieldFactory/AddressFieldDropdown.tsx @@ -8,12 +8,24 @@ import { addressBookSelectors } from 'features/addressBook'; import { Address, Identicon } from 'components/ui'; import './AddressFieldDropdown.scss'; +/** + * @desc The `onChangeOverride` prop needs to work + * with actual events, but also needs a value to be directly passed in + * occasionally. This interface allows us to skip all of the other FormEvent + * properties and methods. + */ +interface FakeFormEvent { + currentTarget: { + value: string; + }; +} + interface StateProps { value?: string; dropdownThreshold?: number; - onChangeOverride?: (ev: React.FormEvent) => void; labelAddresses: ReturnType; currentTo: ReturnType; + onChangeOverride?(ev: React.FormEvent | FakeFormEvent): void; } interface DispatchProps { diff --git a/common/components/AddressFieldFactory/AddressFieldFactory.tsx b/common/components/AddressFieldFactory/AddressFieldFactory.tsx index 7485b169..04fa6c46 100644 --- a/common/components/AddressFieldFactory/AddressFieldFactory.tsx +++ b/common/components/AddressFieldFactory/AddressFieldFactory.tsx @@ -18,8 +18,8 @@ interface OwnProps { showIdenticon?: boolean; value?: string; dropdownThreshold?: number; - onChangeOverride?: (ev: React.FormEvent) => void; withProps(props: CallbackProps): React.ReactElement | null; + onChangeOverride?(ev: React.FormEvent): void; } interface State { @@ -113,8 +113,8 @@ interface DefaultAddressFieldProps { showIdenticon?: boolean; value?: string; dropdownThreshold?: number; - onChangeOverride?: (ev: React.FormEvent) => void; withProps(props: CallbackProps): React.ReactElement | null; + onChangeOverride?(ev: React.FormEvent): void; } const DefaultAddressField: React.SFC = ({ diff --git a/common/components/AddressFieldFactory/AddressInputFactory.tsx b/common/components/AddressFieldFactory/AddressInputFactory.tsx index e63f5c6c..7e5ecec9 100644 --- a/common/components/AddressFieldFactory/AddressInputFactory.tsx +++ b/common/components/AddressFieldFactory/AddressInputFactory.tsx @@ -32,8 +32,8 @@ interface OwnProps { className?: string; value?: string; dropdownThreshold?: number; - onChangeOverride?: (ev: React.FormEvent) => void; onChange(ev: React.FormEvent): void; + onChangeOverride?(ev: React.FormEvent): void; onFocus(ev: React.FormEvent): void; onBlur(ev: React.FormEvent): void; withProps(props: CallbackProps): React.ReactElement | null; @@ -63,7 +63,6 @@ type Props = OwnProps & StateProps; class AddressInputFactoryClass extends Component { public render() { const { - className, label, currentTo, onChange,