Skip to content

Instantly share code, notes, and snippets.

@holgergp
Last active January 14, 2022 09:42
Show Gist options
  • Save holgergp/07e7680832f6f77b66b34d5020c3db6c to your computer and use it in GitHub Desktop.
Save holgergp/07e7680832f6f77b66b34d5020c3db6c to your computer and use it in GitHub Desktop.
Private Field Presence Checks (TypeScript 4.5 Article)
class Person {
#name: string;
constructor(name: string) {
this.#name = name;
}
equals(other: unknown) {
return other &&
typeof other === "object" &&
#name in other && // <- this is new!
this.#name === other.#name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment