Skip to main content
The - operator in TypeScript operates in two distinct compilation contexts: at the type level to declare negative literal types and remove mapping modifiers, and at the value level as a strictly-typed arithmetic operator for binary subtraction and unary negation.

Type-Level Negative Literals

In TypeScript’s type system, the - operator acts as a prefix to define negative numeric and bigint literal types. It modifies a positive literal type into its negative counterpart. Syntax:

Type-Level Mapping Modifier

Within mapped types, the - operator is used as a prefix to subtract (remove) specific modifiers from property signatures. It can be applied to the readonly modifier to remove immutability, or to the ? modifier to remove optionality. Syntax:
  • -readonly: Strips the readonly flag, making the resulting property mutable.
  • -?: Strips the ? flag, making the resulting property required.
Type Resolution Example:

Value-Level Binary Subtraction

At runtime, the - operator performs binary subtraction. Unlike JavaScript, which allows implicit type coercion (e.g., "5" - 2), TypeScript’s static type checker enforces strict operand constraints. Both the left and right operands must resolve to number, bigint, any, or an enum type. Syntax:
Type Checking Behavior:

Value-Level Unary Negation

When used as a unary prefix, the - operator negates the numeric value of its operand. TypeScript enforces strict type constraints, rejecting types that would rely on JavaScript’s implicit runtime coercion to NaN or numbers. Syntax:
Type Checking Behavior:
Tired of Poor TypeScript Skills? Fix That With Deep Grasping!Learn More