从
从as const
常量对象派生广义类型/接口
我有这个:
const usersDefaultValues = {
firstName: '',
isGuest: false
} as const
我想推导出这种类型:
type DefaultValuesSchema = {
firstName: string
isGuest: boolean
}
我想你正在寻找这样的smth:
const usersDefaultValues = {
firstName: '',
isGuest: false
} as const
type M<T> = {
[P in keyof T]: T[P] extends boolean ? boolean : T[P] extends string ? string : never;
}
type Result = M<typeof usersDefaultValues>