我试图定义一个类型Result
,它有一个可选的数据类型.
我当前的类型定义是:
type Result<Data = void> = {
tx: string,
data: Data
}
但它有以下问题(第2行未通过):
const ret: Result<{userId: string}> = {tx: "123", data: {userId: "456"}} // it is GOOD!
const ret: Result = {tx: "123"} // it will complain missing data, how can we pass it?
有人能帮忙吗?非常感谢.