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

272
Views
Typescript: cannot access static fields across packges

I have a package A which is a dependency of package B.

In pkg A, I have a class-based enum defined to serve certain purpose:

export class Stage {
  readonly name: string;

  public static readonly PROD: Stage = new Stage('Prod');
  public static readonly BETA: Stage = new Stage('Beta');
  private constructor(name: string) {
    this.name = name;
  }

  public static fromName(name: string) {
    if (name == 'Prod') return Stage.PROD;
    if (name == 'Beta') return Stage.BETA;
    return null;
  }
}

In pkg B, directly access the static field will throw up errors:

import {Stage} from "pkg-a";

const beta: Stage = Stage.fromName("Beta"); // OK
const prod: Stage = Stage.PROD; // TypeError: Cannot read property 'PROD' of undefined

I have also looked into the compiled JS code of the Stage class in the node_modules. And seems like it did export those static fields:

// tsc compiled js file
class Stage {
    constructor(name) {
        this.name = name;
    }
}
exports.Stage = Stage;
Stage.BETA = new Stage("Beta");
Stage.PROD = new Stage("Prod");

I don't know why I am still getting errors like this.

Does anyone happen to have experience about this issue?

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