I saw this proposal #367 and the relevant context. I understand the need of recurseIntoArrays: false
, but still get a little bit confused.
This #356 (comment) talks about the situation about what problem recurseIntoArrays: true
would cause.
Array types like
(string|undefined)[]
are thorny becauseJSON.parse(JSON.stringify(['a', undefined, 'b']))
becomes['a', null, 'b']
on the other side andnull
is not assignable toundefined
. This is wherePartialDeep
was correctly causing a type failure.
I agree with
In some sense I think PartialDeep is going a little too far.
{foo: string[]}
becomes{foo?: (string|undefined)[]}
but the user probably just intended{foo?: string[]}
which would be fine for serialization.
But I think we didn't consider all the type possibilities.
For serialization,
{ foo: string[] }
should become { foo?: string[] }
instead of { foo?: (string | undefined)[] }
{ foo: { bar: string }[] }
should become { foo?: { bar?: string }[] }
instead of { foo?: ({ bar?: string } | undefined)[] }
or { foo?: { bar: string }[] }
Type-generically, there are 3 results that { foo: T[] }
can become:
{ foo?: T[] }
{ foo?: PartialDeep<T, Options>[] }
{ foo?: PartialDeep<T | undefined, Options>[] }
I think No.2 is what most users want when serializing, not No.1.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too