0

我正在为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。假设我还想添加图标(我在顶部导入),所以添加我要做的是,nameAppIconPropsFeather

name?: React.ComponentProps<typeof AntDesign | typeof Entypo>["name"] | typeof Feather>["name"];

如您所见,这看起来不太好,那么还有其他方法可以编写此接口吗?那么名称字段应该取决于该family字段吗?

4

0 回答 0