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 is a unary decrement operator that subtracts exactly one from its operand. It modifies the operand in place, requiring the operand to be a valid l-value (an assignable memory location, such as a variable or object property). In TypeScript, the static type checker strictly restricts the operand to types number, bigint, or any, preventing the implicit type coercion of strings or booleans that silently occurs in standard JavaScript.
The operator functions in two distinct syntactic positions, which dictate its evaluation order and the resulting value of the expression:
Prefix Decrement (--x)
The decrement operation occurs before the expression is evaluated. It subtracts one from the operand, updates the reference, and evaluates to the newly decremented value.
x--)
The decrement operation occurs after the expression is evaluated. It evaluates to the original value of the operand, and then subtracts one from the underlying reference.
-- operator performs an implicit reassignment (x = x - 1), TypeScript enforces strict mutability and type rules at compile time:
- Immutability: The operand cannot be declared with
const. - Type Safety: The operand must be mathematically valid. Applying it to unsupported types results in
Error TS2356. - Enum Assignment Restriction: Although TypeScript’s arithmetic operand check technically permits enum types (avoiding
Error TS2356), applying--to an enum variable fails during the implicit reassignment phase in TypeScript 5.0+. The decrement operation yields a widenednumbertype, which violates strict type-checking when assigned back to the enum’s strict union type, resulting inError TS2322.
Master TypeScript with Deep Grasping Methodology!Learn More





