TypeScript Basic Types

Like any other languages, TypeScript types are divided into different categories. All types in TypeScript are subtypes of a single top type called the Any type.

Any Type

The Any type is representing any JavaScript value with no constraints. If you don't know about the types, you can use any type to hold any type that are assigning dynamically.

TypeScript Types Example 1

Try it Yourself

2. The Boolean Type

This is very simple datatype which is used to hold true/false value and both JavaScript and TypeScript call as boolean value.

TypeScript Boolean Type Example 3

Try it Yourself

3. The String Type

The string datatype, like other languages is used to hold text data with double quotes (") or single quotes (') to surround text data.

TypeScript String Type Example 3

Try it Yourself

4. The Symbol Type

The symbol datatype is primitive type and represents unique tokens that may be used as keys for object properties.

TypeScript Symbol Type Example 3

Try it Yourself

5. The Void Type

The void datatype is represent absence of having any type and commonly used as return type.

TypeScript Void Type Example 3

Try it Yourself

6. The Null Type

The null datatype is references the one and only value of the Null type and considered a valid value for all primitive types.

TypeScript Null Type Example 3

Try it Yourself

7. The Undefined Type

The undefined datatype is used to uninitialized variables.

TypeScript Undefined Type Example 3

Try it Yourself

8. The Enum Type

The enum datatype, like other languages, is used to give more friendly names to sets of numeric values.

TypeScript Enum Type Example 3

Try it Yourself

Other types are covered in other sections