【发布时间】:2021-10-13 02:02:24
【问题描述】:
我正在尝试在类型中创建一个可以接受任何对象作为输入的函数。我把它定义为
type Props = { onSubmit: (data: Record<string, unknown>) => void};
但是当我尝试将这种类型传递给它时
type SignIn = (data: {email: string, password: string}) => void;
我收到此错误
Type 'SignIn' is not assignable to type '(data: Record<string, unknown>) => void'.
Types of parameters 'data' and 'data' are incompatible.
Type 'Record<string, unknown>' is missing the following properties from type '{ email: string; password: string; }': email, password
错误的完整示例是here
【问题讨论】:
标签: typescript