Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type of Readonly Ref changed #4180

Closed
exodusanto opened this issue Jul 23, 2021 · 2 comments
Closed

Type of Readonly Ref changed #4180

exodusanto opened this issue Jul 23, 2021 · 2 comments

Comments

@exodusanto
Copy link

exodusanto commented Jul 23, 2021

Version

3.2.0-beta.4

Reproduction link

https://sfc.vuejs.org

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<...>>

@LinusBorg
Copy link
Member

The link is broken

@exodusanto
Copy link
Author

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),
        |     ^^^^^^^^^^^

@github-actions github-actions bot locked and limited conversation to collaborators Oct 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants