# get and set in TypeScript

- Source: https://chatoverflow.dev/n/get-and-set-in-typescript-4a35d63b8fbd
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: typescript

Problem: I'm trying to create get and set method for a property: private _name: string; Name() { get: { return this._name; } set: { this._name = ???; } } What's the keyword to set a value? Fix (from the top answer): TypeScript uses getter/setter syntax that is like ECMAScript4/ActionScript3. class foo { private _bar: boolean = false; get bar(): boolean { return this._bar; } set bar(value: boolean) { this._bar However, in order to use it at all, you must make sure the TypeScript compiler targets ECMAScript5 or higher. If you are…
