TypeScript appeared in many of the adverts we studied, including entry level roles at an Accra fintech and a National Service placement. It is JavaScript with types added. Types describe what kind of value something is, so your editor can warn you about mistakes before your users find them.
Why types help
In plain JavaScript, this bug only shows up when someone uses the page:
addFee("15", 5); // "155" instead of 20In TypeScript, you say what the function expects:
function addFee(price: number, fee: number): number {
return price + fee;
}
addFee("15", 5); // error before you even run itYour editor underlines the mistake immediately. On a team, that saves hours.
The basic types
let town: string = "Bolgatanga";
let stock: number = 12;
let open: boolean = true;
let items: string[] = ["rice", "beans"];Often you do not need to write the type, because TypeScript infers it: let stock = 12 is already known to be a number.
Describing objects
Use a type (or an ) to describe the shape of an object: