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.
-= (subtraction assignment) operator subtracts the value of the right operand from the left operand and assigns the resulting value to the left operand. Crucially, the left operand is evaluated exactly once. This makes it semantically distinct from a standard subtraction and assignment (x = x - y) when the left operand contains side effects, such as a property access with a post-incrementing index.
Evaluation Semantics
Because the left operand is evaluated only once, compound assignments are safe to use with expressions that mutate state during evaluation.Type Constraints in TypeScript
Unlike JavaScript, which permits implicit type coercion during arithmetic operations (e.g., subtracting a number from a numeric string), TypeScript enforces strict type checking on the-= operator at compile time.
- Valid Types: Both operands must resolve to
any,number,bigint, or anenumtype. - Type Homogeneity: You cannot mix
numberandbigintoperands. They must be of the same type, or explicitly cast. - Mutability: The left operand must be a valid, mutable l-value (e.g., a variable declared with
letorvar, or a mutable object property). - Enum Assignment Restrictions: While enums are valid operands for the subtraction itself, assigning the result back to an enum variable via
-=is restricted in TypeScript 5.0 and later. The arithmetic subtraction of an enum evaluates to anumber, which cannot be assigned back to an enum type.
Syntax and Type Checking Examples
Return Value
The-= operation evaluates to the assigned value. This allows for chained assignments, though this practice is generally discouraged for readability.
Master TypeScript with Deep Grasping Methodology!Learn More





