【发布时间】:2022-12-22 03:29:21
【问题描述】:
type ComponentType = (...args: any) => any;
type PlatformNotificationProps<TIcon extends ComponentType = ComponentType> = {
component: TIcon;
arg: Parameters<TIcon>[0];
};
const PlatformNotification = (props: PlatformNotificationProps) => {};
const Icon = (name: string) => '';
const result = PlatformNotification({
component: Icon,
arg: 100,
});
在这种情况下,或“arg”不正确,应该是一个字符串,或者组件不正确,应该接受数字而不是字符串。 我希望在控制台中看到错误,但一切正常。
我如何为这种情况编写类型?
【问题讨论】:
标签: typescript