You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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';interfaceTestReadonlyObject{// The property value type does not extend object, so it will not recursively make the object writable.readonlytestObjectOrNull: {readonlytestProperty: number}|null;}constinput: 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;}});
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)
The text was updated successfully, but these errors were encountered:
Methuselah96
changed the title
Draft type no longer handles deeply nested readonly object with mixed property type correctly
Draft type no longer handles deeply nested readonly object with mixed property value types correctly
Jan 16, 2023
Methuselah96
changed the title
Draft type no longer handles deeply nested readonly object with mixed property value types correctly
Draft type no longer handles nested readonly objects with mixed property value types correctly
Jan 16, 2023
🐛 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 ofJsonObject
becauseJsonObject
'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 theobject
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 theJsonObject
type and in other cases).Link to repro
Playground Link
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.
setUseProxies(true)
setUseProxies(false)
(ES5 only)The text was updated successfully, but these errors were encountered: