#something
is ECMAScript's way of making a property private natively. It's supported since TypeScript 3.8. TypeScript normally add in its releases what's been Stage 3
See more published in 2019-07 by Axel Raushmayer's blog private class fields and in Impatient JS, section 29.3 Private data for classes
This Gist shows different build outputs of the following.
export interface LivingBeing {
age: number
}
/**
* The purpose of this example
*/
export class Person implements LivingBeing {
#age = 0;
constructor(public name: string) {}
get age(): number {
return this.#age;
}
}
In modern runtime, this would be compiled into ECMAScript 2015 as
function __classPrivateFieldGet(receiver, state, kind, f) {
// ...
}
var _age;
/**
* The purpose of this example
*/
class Person {
constructor(name) {
this.name = name;
_age.set(this, 0);
}
get age() {
return __classPrivateFieldGet(this, _age);
}
}
_age = new WeakMap();
In an older runtime, this would become about 2000 lines of code though.