When an object with private properties or methods is passed to ref()
or reactive()
, the resulting proxy no longer contains the private properties.
Consider the following class:
class Pirate {
name: string;
age: number;
private dream : string;
constructor(name: string, age: number, dream: string) {
this.name = name;
this.age = age;
this.dream = dream;
}
}
Creating a ref of type Pirate
will lead to a Typescript error stating :
Property 'dream' is missing...
You can view an example here.
I would like to create a reactive object while maintaining the confidentiality of private properties. Is it possible in Vue 3?
The same issue occurs with reactive()
as well.