Type of Readonly Ref changed
Version
3.2.0-beta.4
Reproduction link
Steps to reproduce
const object = ref({ count: 1 });
typeof readonly(object);
const variable = ref(1);
typeof readonly(variable);
What is expected?
const object = ref({ count: 1 });
readonly(object); // Ref<DeepReadonly<...>>
const variable = ref(1);
readonly(variable); // Ref<Readonly<number>>
What is actually happening?
const object = ref({ count: 1 });
readonly(object); // DeepReadonly<Ref<...>>
const variable = ref(1);
readonly(variable); // DeepReadonly<Ref<number>>
I'm using the readonly
function with a Ref<Object[]>
.
In 3.1.5 the result of function call is a Ref<DeepReadonly<Object[]>>
and with a simple ref like Ref<string>
the result is Ref<Readonly<string>>
Since 3.2.0-beta.1 a primitive type like string the result is no more Ref<Readonly<string>>
but DeepReadonly<Ref<string>>
and using the ref in a watch context the new / old value seems to be the ref instead of the value changed.
And the object from Ref<DeepReadonly<...>>
became DeepReadonly<Ref<...>>
This is the compiler error after update from 3.1.5 to 3.2.0-beta.4
TS2322: Type '{ readonly value: readonly { readonly label: string; readonly value: string; }[]; readonly dep?: ReadonlySet<{ readonly fn: () => any; readonly scheduler: EffectScheduler | null; readonly active: boolean; ... 7 more ...; readonly stop: () => void; }> | undefined; readonly [RefSymbol]: true; }' is not assignable to type 'Ref<readonly PlacePrediction[]>'.
Types of property 'dep' are incompatible.
Type 'ReadonlySet<{ readonly fn: () => any; readonly scheduler: EffectScheduler | null; readonly active: boolean; readonly deps: readonly ReadonlySet<...>[]; readonly computed?: boolean | undefined; ... 5 more ...; readonly stop: () => void; }> | undefined' is not assignable to type 'Dep | undefined'.
185 | query,
186 | loading: readonly(loading),
> 187 | suggestions: readonly(suggestions),
| ^^^^^^^^^^^