TypeScript adds type annotations to JavaScript variables using a : followed by the type in source . The most common primitive types are:

const bootupMessage: string = "starting server...";
const port: number = 3000;
const isOnline: boolean = true;
const noValue: null = null;
const notDefined: undefined = undefined;

If a value doesn’t match its type, the TypeScript compiler reports an error:

const bootupMessage: string = 123;
// Error: Type 'number' is not assignable to type 'string'.