Home > types-kit > ReplacePick
Create a type that replace the values in the corresponding keys.
Signature:
export type ReplacePick<
T,
KeysArr extends readonly Keys<T>[],
ValuesArr extends Fill<KeysArr['length'], unknown>,
> = {
[P in keyof T]: InternalReplacePickValue<P, T[P], KeysArr, ValuesArr>
}References: Keys, Fill, InternalReplacePickValue
interface Props {
readonly a?: {
d?: boolean
}
b?: number
c: number
}
// Expect: { readonly a?: number, b?: number, c: string }
// ['a.d','c'] means the keys to replace, [string, string] means the values to map
type new Props = DeepReplacePick<Props, ['a','c'], [number, string]>