【发布时间】:2022-09-27 23:18:24
【问题描述】:
我有一个名为data 的变量,它是一个array,其中包含一个function 和一个object。我想为此定义一个模型而不是使用any,但不幸的是我不知道如何,谢谢你的帮助。
interface Person {
name: string;
age: number;
}
interface data {
// how do i write ?
person: Person;
handleShowPerson: () => void ;
}
export default function App() {
const person: Person = { name: \"nil\", age: 30 };
const handleShowPerson = ({ name, age }: person) => (
<h1>
My name is {name} and I am {age} years old`)
</h1>
);
const data: data = [person, handleShowPerson];
}
-
根据使用情况,这似乎是 tuple、
person和handleShowPerson不是任何事物的属性。 -
现在你不知道我如何为数据变量定义一个接口吗? @jonrsharpe
-
为什么要将其定义为接口?你已经有了一个正在运行的接口在元组。
标签: reactjs typescript