Can tsignonActativeChange
缩略语
type ActivityType = {
id: string;
name: string;
}
const onChange = <TOption extends {}>(value: TOption) => {
console.log(value);
}
const onActivityChange = (value: ActivityType) => {
console.log(value);
}
// error
const handler: typeof onChange = onActivityChange;
错误:
Type (value: ActivityType) => void is not assignable to type <TOption extends {}>(value: TOption) => void .
Types of parameters value and value are incompatible.
Type TOption is not assignable to type ActivityType .
Type {} is missing the following properties from type ActivityType : id, name
如何加以确定,并节省<代码>onChange类型背后的类型?
http://www.ohchr.org。
使用反应剂量:
const onActivityChange = (value: ActivityType) => {
console.log(value);
}
<Dropdown
isError={!!errors.activity}
id="activity"
// error
onChange={onActivityChange}
data-testid="field-activity"
>
<Option />
</Dropdown>
export type Props = {
value?: string;
onChange: <TOption extends {}>(value: TOption) => void;
is错误: boolean;
extraButtons?: ReactNode;
} & ComponentProps< div >