Based on the name of a property, I am applying Required<T> for this property.
E.g: Transform
{
x: {
id?: string | undefined,
...
},
...
}
to
{
x: {
id: string,
...
},
...
}
I only found the internal type TransformObjectDeep to help me with this use case.
import { type ComposeLeft, type Fn } from 'hotscript'
import { type TransformObjectDeep } from 'hotscript/dist/internals/objects/impl/objects'
import { type SetRequired } from 'type-fest'
interface IdRequiredFn extends Fn {
return: this['args'] extends [infer obj]
? obj extends { id?: string }
? SetRequired<obj, 'id'>
: obj
: never
}
type FixPayloadTypes<T> = TransformObjectDeep<
ComposeLeft<[IdRequiredFn]>, // I am also using other transform Fns
T
>
But by using TransformObjectDeep all properties with Array<T> type get "unioned" with undefined, causing access to the items to fail.
What is the reason for adding undefined to the type?
Thank you so much for this library! I am using it to patch deeply nested auto-generated types from https://github.com/payloadcms/payload.
Based on the name of a property, I am applying
Required<T>
for this property.E.g: Transform
to
I only found the internal type
TransformObjectDeep
to help me with this use case.But by using
TransformObjectDeep
all properties withArray<T>
type get "unioned" withundefined
, causing access to the items to fail. What is the reason for addingundefined
to the type?