我正在为expo-vector-icons
. 这是目前为止的界面。
import { AntDesign, Entypom, Feather } from "@expo/vector-icons";
type AppIconFamilies = {
AntDesign: typeof AntDesign;
Entypo: typeof Entypo;
}
export interface AppIconProps {
family?: keyof AppIconFamilies;
name?: React.ComponentProps<typeof AntDesign | typeof Entypo>["name"];
}
我想用打字稿生成相同的道具。但我看到我正在复制界面中的name
字段。AppIconProps
有什么办法可以消除这种重复吗?
基本上,现在AntDesign
和接口领域都有Entypo
。假设我还想添加图标(我在顶部导入),所以添加我要做的是,name
AppIconProps
Feather
name?: React.ComponentProps<typeof AntDesign | typeof Entypo>["name"] | typeof Feather>["name"];
如您所见,这看起来不太好,那么还有其他方法可以编写此接口吗?那么名称字段应该取决于该family
字段吗?