If you want to use getter in a class, then it must be static:
export class Foo{
private static _instance;
private constructor(){};
public static getInstance(){}
}
The fact is that although the compiler will use this confidential visibility, at run time it will still be possible to bypass it, even unintentionally, if, for example, someone uses it from javascript directly.
If you apply it with a module / namespace, you can completely hide it:
:
export interface IFoo {}
class Foo implements IFoo {}
var instance: Foo;
export function getFooInstance(): IFoo {
return instance;
}
, IFoo ( ), - , , .
:
namespace Foo {
export interface IFoo {}
class FooClass implements IFoo {}
const instance = new FooClass();
export function getInstance(): IFoo {
return instance;
}
}