import React from'react';
// 定义映射类型
type CustomProps<T extends Record<string, unknown>> = {
title: string;
description: string;
} & T;
// 定义Card组件
const Card = <T extends Record<string, unknown>>({ title, description, ...customProps }: CustomProps<T>) => {
return (
<div>
<h2>{title}</h2>
<p>{description}</p>
{/* 这里可以根据customProps进行自定义渲染 */}
</div>
);
};
// 使用示例
const App: React.FC = () => {
const customData = { link: 'https://example.com' };
return (
<Card title="示例卡片" description="这是一个示例描述" {...customData} />
);
};
export default App;