Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!