Draft type no longer handles nested readonly objects with mixed property value types correctly
Methuselah96 opened this issue Β· comments
π Bug Report
The fix in #990 does not seem to properly fix #839 and also breaks other scenarios. It should probably be reverted.
That PR "fixes" the issue of recursive types by bailing out of the recursion if the property's value type does not extend object
. This "works" in the case of JsonObject
because JsonObject
's property's value type is a union of objects and primitives, and so it doesn't recurse on the object's properties because the property's value type does not extend the object
type.
This is problematic because it won't remove the readonly
modifier from nested objects if they have mixed property value types (both in the case of the JsonObject
type and in other cases).
Link to repro
import { produce } from 'immer';
interface TestReadonlyObject {
// The property value type does not extend object, so it will not recursively make the object writable.
readonly testObjectOrNull: { readonly testProperty: number } | null;
}
const input: TestReadonlyObject = { testObjectOrNull: null };
produce(input, (draft) => {
if (draft.testObjectOrNull) {
// Errors because `testProperty` is still readonly, even though it shouldn't be.
draft.testObjectOrNull.testProperty = 5;
}
});
To Reproduce
See above.
Observed behavior
There is a TypeScript error.
Expected behavior
There should be no TypeScript error.
Environment
We only accept bug reports against the latest Immer version.
- Immer version: 9.0.18
- I filed this report against the latest version of Immer
- Occurs with
setUseProxies(true)
- Occurs with
setUseProxies(false)
(ES5 only)
Hi,
Can you release this change? The break went out patch release that has a tendency to automatically get pulled in.
Thanks!
π This issue has been resolved in version 9.0.19 π
The release is available on:
Your semantic-release bot π¦π