TypeScript Simple Types

TypeScript tutorial

TypeScript Simple Types

TypeScript Simple Types are the basic data types used to define what kind of value a variable can hold.

They help prevent errors and make code more readable.


number

Used for integers and floating-point numbers.


string

Used for text values.


boolean

Used for true / false values.


any

Allows any type of value (avoid using when possible).

  •  Use any only when you don’t know the type.

unknown (Safer than any)

Requires type checking before use.


 


null and undefined

Used for empty or missing values.

With strictNullChecks:


array

Used to store multiple values of the same type.


tuple

Array with fixed number and type of elements.


enum

Defines a set of named constants.


 


void

Used when a function returns nothing.


never

Used when a function never returns.


 Type Inference

TypeScript can automatically detect types.


 Simple Types Summary

TypePurpose
numberNumeric values
stringText
booleantrue/false
anyAny type
unknownSafe any
nullEmpty
undefinedNot assigned
arrayList of values
tupleFixed structure
enumNamed constants
voidNo return
neverNever returns

You may also like...