You may only one value for each property key on anything. This is true for plain objects, and it's true for class instance methods and it's true for static class methods.
So you my not have two methods with the exact same name where one is private
and one is public
. They must have different names.
Such as:
export class MyClass {
public static methodX(arg: ArgTypeA): void {
// method implementation, it will call the private method methodX(arg: ArgTypeB)
}
private static methodXCoreImplementation(arg: ArgTypeB): void {
// method implementation
}
}
One way to achieve something close to this would be to use private fields. That uses the #
prefix to declare a private field which is completely inaccessible to the outside.
And foo
is technically a different property name to #foo
, so this should work:
export class MyClass {
public static methodX(arg: string): void {
this.#methodX(arg)
}
static #methodX(arg: string): void {
console.log('hello from private field method:', arg)
}
}
MyClass.methodX('test') // "hello from private field method:", "test"
See Playground