In TypeScript, an override setter is aDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
set accessor in a derived class annotated with the override keyword, explicitly declaring the intent to replace the assignment behavior of a property or setter inherited from a base class. When the noImplicitOverride compiler option is enabled in tsconfig.json, the compiler enforces a strict structural check, emitting an error if the base class does not possess a corresponding member to override.
Technical Mechanics
1. Target Resolution and Runtime Caveats An override setter can legally target and replace two types of base class members: an existingset accessor, or a standard class property.
Overriding a standard class property introduces a critical runtime caveat. If the useDefineForClassFields compiler option is enabled (which is the default for modern targets like ES2022 and later), the base class initializes the property directly on the instance. This instance property will shadow the derived class’s prototype accessors at runtime, meaning the setter will never be invoked when assigning to the property during or after base class instantiation.
- Readable Properties: If the base class defines a readable property (either as a standard property or via a
getaccessor), the derived class can widen the setter’s parameter type as long as it explicitly provides agetaccessor. This derived getter must return a type that is covariant (assignable) to the base class’s read type. - Write-Only Properties: If both the base and derived classes define only
setaccessors (omitting getters), the property is write-only. Write-only properties are strictly contravariant, meaning the derived setter can be widened without any covariant read-type checks. - Missing Read Contract: If the base class defines a readable property but the derived class overrides only the setter, the derived property becomes write-only. This results in a compiler error because the derived class fails to fulfill the read contract required by the base class.
public, the override setter must remain public. If the base setter is protected, the override setter can remain protected or be widened to public.
4. Getter/Setter Prototype Shadowing
In JavaScript prototype chains, defining a setter on a derived prototype shadows the entire property descriptor of the base class. Consequently, overriding only the set accessor in the derived class does not automatically inherit the base get accessor. To maintain both read and write capabilities when extending behavior, the derived class must explicitly define both accessors, utilizing super calls if it needs to invoke the base class’s accessor logic.
Master TypeScript with Deep Grasping Methodology!Learn More





