diff --git a/packages/zent/src/radio/AbstractRadio.ts b/packages/zent/src/radio/AbstractRadio.ts index adbecea434..ea2e00b09f 100644 --- a/packages/zent/src/radio/AbstractRadio.ts +++ b/packages/zent/src/radio/AbstractRadio.ts @@ -20,7 +20,7 @@ export interface IRadioProps { className?: string; prefix?: string; checked?: boolean; - onChange?: (e: IRadioEvent) => void; + onChange: (e: IRadioEvent) => void; style?: React.CSSProperties; } @@ -42,7 +42,7 @@ abstract class AbstractRadio extends Component { // event liftup // link: https://facebook.github.io/react/docs/lifting-state-up.html - handleChange = evt => { + handleChange: React.ChangeEventHandler = evt => { const { props, context } = this; const e: IRadioEvent = { target: { diff --git a/packages/zent/src/radio/Group.tsx b/packages/zent/src/radio/Group.tsx index 979111a13f..1b60e6fa8a 100644 --- a/packages/zent/src/radio/Group.tsx +++ b/packages/zent/src/radio/Group.tsx @@ -6,21 +6,22 @@ import eq from 'lodash-es/eq'; import memoize from '../utils/memorize-one'; import GroupContext from './GroupContext'; +import { IRadioEvent } from './AbstractRadio'; const GroupContextProvider = GroupContext.Provider; -export interface IGroupProps { - value: any; - disabled?: boolean; - readOnly?: boolean; - onChange: React.ChangeEventHandler; - isValueEqual?: (value1: any, value2: any) => boolean; +export interface IRadioGroupProps { + value: unknown; + disabled: boolean; + readOnly: boolean; + onChange: (e: IRadioEvent) => void; + isValueEqual: (value1: unknown, value2: unknown) => boolean; className?: string; prefix?: string; style?: React.CSSProperties; } -export class RadioGroup extends Component { +export class RadioGroup extends Component { static defaultProps = { prefix: 'zent', className: '', @@ -31,15 +32,22 @@ export class RadioGroup extends Component { onChange: noop, }; - getGroupContext = memoize((value, disabled, readOnly, isValueEqual) => ({ - value, - disabled, - readOnly, - isValueEqual, - onRadioChange: this.onRadioChange, - })); + getGroupContext = memoize( + ( + value: unknown, + disabled: boolean, + readOnly: boolean, + isValueEqual: (value1: unknown, value2: unknown) => boolean + ) => ({ + value, + disabled, + readOnly, + isValueEqual, + onRadioChange: this.onRadioChange, + }) + ); - onRadioChange = e => { + onRadioChange = (e: IRadioEvent) => { this.props.onChange(e); }; @@ -55,10 +63,12 @@ export class RadioGroup extends Component { children, } = this.props; - const classString = classNames({ - [`${prefix}-radio-group`]: true, - [className]: !!className, - }); + const classString = classNames( + { + [`${prefix}-radio-group`]: true, + }, + className + ); return (