【发布时间】:2021-12-16 13:17:24
【问题描述】:
我们在代码库中使用cleanNullOrUndefined 函数,如果键的值为空或未定义,它会删除对象中的键。这不是很好的类型,只是返回原始对象的Partial,这会在其他地方给出一些错误。
我们需要输入函数以返回对象,删除 null 或未定义的键并推断其他键的类型。
例子:
const obj = {
a: 1,
b: 'string',
c: false,
d: null,
e: undefined
}
// Desired return type
interface ReturnType {
a: number,
b: string,
c: boolean
}
我似乎无法理解如何做到这一点。
【问题讨论】:
标签: typescript