省略效用函数,$ Omit?或$ PropertyType的缩写?

时间:2017-09-04 22:18:59

标签: flowtype

很多次我发现自己使用省略,这需要大量使用$PropertyType

对于instnace:

type EntityBase = {
    id: EntityId,
    created_at: DateStr
}

type Profile = {
    ...($Diff<EntityBase, {created_at:$PropertyType<EntityBase, 'created_at'>}>), // omit(created_at)
}

对于仅仅尝试省略一个密钥,这是很多不可读的问题。 Profile的类型只是id的一个键的对象。

$Omit是否有$PropertyType和/或缩写?

以下是$PropertyType可以变成大量输入的方式:

type Props = {
    authorAvatar: $PropertyType<Profile, 'avatar'>,
    authorName: $PropertyType<Profile, 'name'>,
    commentsCnt: number,
    created_at: $PropertyType<StoryType, 'created_at'>,
    socialBoxId: $PropertyType<StoryType, 'socialBoxId'>,
    story_line: $PropertyType<StoryType, 'story_line'>,
    story_text: $PropertyType<StoryType, 'story_text'>
}

如果可以这样做会很棒:

type Props = {
    authorAvatar: Profile.avatar,
    authorName: Profile.name,
    commentsCnt: number,
    created_at: StoryType.created_at,
    socialBoxId: StoryType.socialBoxId,
    story_line: StoryType.story_line,
    story_text: StoryType.story_text
}

0 个答案:

没有答案