In my attempt to develop a type called Optional<T, TProps>
, where T
represents the initial type and TProps
is a union type of properties that need to be optional.
As an illustration:
type A = Optional<{a: string, b: string}, 'a'>
const a: A = {b: 'foo'} // No Error
I had anticipated this approach to work flawlessly but unfortunately it's not functioning as expected:
type Optional<T extends object, TProps extends keyof T> =
{[TKey in keyof T]: TKey extends TProps ? T[TKey] | never : T[TKey]}