TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
- operator in TypeScript functions in two distinct contexts: at the type level as a mapping modifier to remove property constraints, and at runtime as a standard arithmetic subtraction and unary negation operator subject to strict static type checking.
Type-Level Semantics: Mapping Modifiers
In TypeScript’s type system, the- operator is used exclusively within mapped types to subtract (remove) specific modifiers from properties during type transformations. It can be applied to the readonly and ? (optional) modifiers.
Syntax:
-readonly: Strips thereadonlymodifier from the property key, making the resulting property mutable.-?: Strips the?modifier from the property key, making the resulting property strictly required and removingundefinedfrom the property’s union type (unlessundefinedis explicitly defined in the base type).
Runtime Semantics: Arithmetic and Unary Negation
At runtime, TypeScript inherits JavaScript’s- operator behavior but applies strict static type checking to the operands to prevent unintended implicit type coercion.
Binary Subtraction (A - B)
The compiler requires both operands to be of type number, bigint, any, or a numeric enum. TypeScript will throw a compilation error if the operands are of incompatible types or if you attempt to mix number and bigint.
-A)
When used as a unary prefix, the - operator converts the operand into a numeric value and negates it. TypeScript enforces that the operand must be of a type mathematically compatible with negation (number, bigint, any, or a numeric enum).
Master TypeScript with Deep Grasping Methodology!Learn More





