export interface BookProps {
link: string;
title: string;
image: string;
author: string;
discount: string;
publisher: string;
description: string;
}
有没有办法简洁的表达界面中所有元素都是字符串类型?
您可以使用索引属性来实现通用接口定义。
interface Book {
[prop: string]: string;
}
const nineteenEightyFour: Book = {
link: "https://...",
title: "nineteenEightyFour",
....
}
Ts应该对此感到足够高兴。