In my TypeScript project, I'm working on creating a constants file that will provide an Opaque token object when
ServiceConstants.AUTH_SERVICE_TOKEN
is called.
I've experimented with two approaches:
Using ServiceConstants.ts as a namespace
export namespace ServiceConstants {
export const AUTH_SERVICE_TOKEN: OpaqueToken = new OpaqueToken('AuthService');
}
Or using ServiceConstants.ts as a class
export class ServiceConstants {
public static AUTH_SERVICE_TOKEN: OpaqueToken = new OpaqueToken('AuthService');
}
However, whenever I try to access this object, I encounter an error message:
Uncaught TypeError: Cannot read property 'AUTH_SERVICE_TOKEN' of undefined
How can I initialize the AUTH_SERVICE_TOKEN so that it can be simply accessed by calling
ServiceConstants.AUTH_SERVICE_TOKEN
, without needing to create a new object or encountering this error? Initially, I believed that using the namespace would suffice, but it appears that isn't the case.
Thank you
JT