小编sin*_*dre的帖子

分隔联合类型的每个成员

我有一个生成的联合类型,看起来像:

type Result = { type: 'car' } | { type: 'boat' }
Run Code Online (Sandbox Code Playgroud)

如何将它们分开,以便为每个类型创建单独的类型?例如:

type BoatResult = { type: 'boat' }
type CarResult = { type: 'card' }
Run Code Online (Sandbox Code Playgroud)

它们必须从原始Result类型创建。

discriminated-union typescript

4
推荐指数
1
解决办法
1793
查看次数

标签 统计

discriminated-union ×1

typescript ×1