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

146
Vistas
How to access private member of a class from a static method of the same class in TypeScript?
export class A {  
    private variableType: number | string;  
    public static func ( x: variableType) {
      //code 
    } 
}

How do I make x of the type variableType? I tried using 'this.variableType' but it's not available in a static member of the class. Also 'A.variableType' complains that A is a type but is being used as a namespace here.

Note- There were a lot of similar questions but I didn't get the solution to this. Sorry if this has already been answered.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

For your case, I'd do this way below by creating a type

type VariableType = number | string;

export class A {  
    private variableType: VariableType;  
    public static func (x: VariableType) {
      //code 
    } 
}

Alternatively,

public static func (x: A['variableType') {
  //code 
} 

it also works but I feel like using type is a bit cleaner.

about 4 years ago · Juan Pablo Isaza Denunciar
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