在 Nodejs 中,我可以声明如下内容(注意 productType )。这在 F# 中的 Record 或 struct 中可能吗?我不想使用类 - 我不认为我可以使用枚举,因为我想存储“S”或“G”
export interface Product {
_id?: string
sku: string
name: string
productType: 'S' | 'G' //S, G ( simple , grouped )
}
Run Code Online (Sandbox Code Playgroud)
您可以使用有区别的联合。
代码将如下所示:
type ProductType = Simple | Grouped
type Product =
{ Id : string option // I don't know NodeJS, so I think that 'id?' is optional
Sku : string
Name : string
Type : ProductType }
Run Code Online (Sandbox Code Playgroud)