Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joselvelez/5bc291eea462492ff1ea160dd66550fc to your computer and use it in GitHub Desktop.
Save joselvelez/5bc291eea462492ff1ea160dd66550fc to your computer and use it in GitHub Desktop.
Practicing with TypeScript Class readonly modifier
class TestReadOnly {
readonly testProp: string = "sup man";
constructor(newValue?: string) {
if (newValue !== undefined) {
this.testProp = newValue;
}
}
}
const g = new TestReadOnly();
console.log(g.testProp);
const z = new TestReadOnly("a new value");
console.log(z.testProp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment