Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

126
Vistas
why typescript class expose all private members?

I'm confused with typescript class, the private member doesn't work as it should.

class TClass {

  public pu = 1;
  private pv = 2

  constructor(private ar = 1) {

  }

}

const f1 = new TClass();
console.log({ ...f1 })

the output of this is

[LOG]: {
  "ar": 1,
  "pu": 1,
  "pv": 2
} 

as you can see all the private members are exposed!

but if I want to write a custom class I could use something like this

const JClass= function(ar=1){
  const pv=2;
  this.pu=1;
};

const f2= new JClass();
console.log({...f2})

and the output will be

[LOG]: {
  "pu": 1
} 

if you want to play here is a playground

so my question is how to make the typescript really respect the meaning of private?

about 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda