mirror of
https://github.com/type-challenges/type-challenges.git
synced 2026-02-01 15:47:22 +00:00
RequiredByKeys

by jiangshan @jiangshanmeta
Implement a generic RequiredByKeys<T, K> which takes two type argument T and K.
K specify the set of properties of T that should set to be required. When K is not provided, it should make all properties required just like the normal Required<T>.
For example
interface User {
name?: string
age?: number
address?: string
}
type UserPartialName = RequiredByKeys<User, 'name'> // { name: string; age?: number; address?: string }