> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# TypeScript Public Getter

A public getter in TypeScript is an accessor method defined with the `get` keyword and the `public` access modifier that intercepts read operations on a class property. It allows a method to be accessed syntactically as a standard property while executing underlying logic to compute or retrieve the returned value.

```typescript theme={"dark"}
class ClassName {
    public get propertyName(): ReturnType {
        // execution logic
        return value;
    }
}
```

## Technical Characteristics

**Visibility and Access**
The `public` modifier exposes the member to the public API of the class instance, meaning it can be accessed externally via class instances, by derived subclasses, and internally within the class. Because TypeScript class members are `public` by default, the explicit `public` keyword is optional but often used for strict stylistic adherence.

**Parameter Constraints**
A getter cannot accept any parameters. Attempting to define a parameter in a `get` accessor will result in a compiler error (`TS1094: A 'get' accessor cannot have parameters`).

**Type Inference and Return Types**
TypeScript automatically infers the type of the exposed property based on the getter's return type. While a getter is conceptually designed to return a value, TypeScript allows getters without a `return` statement (which implicitly infers a return type of `void`), provided the `noImplicitReturns` compiler flag is not enabled. If a corresponding `set` accessor is defined for the same property name, the return type of the getter must be assignable to the parameter type of the setter.

**Readonly Inference**
If a public getter is defined without a corresponding setter, TypeScript automatically infers the property as `readonly` at the type level. Any attempt to assign a value to this property will throw a compilation error (`TS2540: Cannot assign to 'propertyName' because it is a read-only property`).

**Compilation Target**
Getters are an ECMAScript feature. The TypeScript compiler requires the `--target` flag to be set to `ES5` or higher to support accessors. When the compilation target is set to `ES5`, `get` accessors are transpiled into `Object.defineProperty()` calls utilizing the `get` property descriptor. When targeting `ES6` (ES2015) or higher, TypeScript preserves the native ECMAScript class `get` syntax.

## Mechanical Example

```typescript theme={"dark"}
class SensorData {
    private _rawInput: number = 25;

    // Explicitly typed public getter
    public get normalizedInput(): number {
        return this._rawInput * 1.5;
    }
}

const sensor = new SensorData();

// The getter is accessed via property dot-notation, omitting parentheses
const data = sensor.normalizedInput; 

// Error TS2540: Cannot assign to 'normalizedInput' because it is a read-only property.
// sensor.normalizedInput = 50; 
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor TypeScript Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
