TypeScript Type Operators
In TypeScript, type operators are constructs that allow you to perform operations on types. These operators provide powerful mechanisms for defining and manipulating types in a flexible and expressive manner.
Name | Description | Syntax |
---|---|---|
typeof | Obtains the type of a variable, function, or property. | let x = 10; <br>type XType = typeof x; <br>// XType is 'number' |
keyof | Obtains the keys (property names) of a type. | type Person = { name: string; age: number }; <br>type PersonKeys = keyof Person; <br>`// PersonKeys is ‘name’ |
Mapped Types | Allows creating new types based on the properties of existing types. | type Optional<T> = { [K in keyof T]?: T[K] }; |
Conditional Types | Allows expressing a type based on a condition. | type TypeName<T> = T extends string ? 'string' : 'non-string'; |
TypeScript Operators
TypeScript operators are symbols or keywords that perform operations on one or more operands. In this article, we are going to learn various types of TypeScript Operators.
Below are the different TypeScript Operators:
Table of Content
- TypeScript Arithmetic operators
- TypeScript Logical operators
- TypeScript Relational operators
- TypeScript Bitwise operators
- TypeScript Assignment operators
- TypeScript Ternary/conditional operator
- TypeScript Type Operators
- TypeScript String Operators
Contact Us