Created
May 23, 2021 16:13
-
-
Save joselvelez/5bc291eea462492ff1ea160dd66550fc to your computer and use it in GitHub Desktop.
Practicing with TypeScript Class readonly modifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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