Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

152
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda