TypeScript in Minutes: Types, Functions, Classes and Interfaces
A fast introduction to TypeScript: installation, compilation, core types, typed functions, classes and interfaces.

1. Start a tiny TypeScript project
Project setupbash
mkdir ts-basics
cd ts-basics
npm init -y
npm install --save-dev typescript
npx tsc --initA tsconfig.json marks the project root and stores compiler options. Running npx tsc checks and compiles according to that configuration.
2. Primitive types and inference
basics.tsts
let studentName: string = 'Mireille';
let age: number = 19;
let paid: boolean = false;
// TypeScript can infer the type too:
let city = 'Douala'; // string| Type | Example | Typical use |
|---|---|---|
| string | 'Clarvo' | Names, labels, IDs when numeric operations are not needed |
| number | 42 | Scores, prices, counts |
| boolean | true | Flags and yes/no state |
| string[] | ['React','C'] | Lists of strings |
| unknown | value from an unsafe boundary | Forces you to check before use |
3. Arrays and object shapes
Typed student datats
type Student = {
id: string;
name: string;
score?: number;
};
const students: Student[] = [
{ id: 's1', name: 'Mireille', score: 16 },
{ id: 's2', name: 'Joel' },
];4. Functions: type the boundary
Typed functionts
function percentage(score: number, total: number): number {
if (total <= 0) throw new Error('total must be positive');
return (score / total) * 100;
}
console.log(percentage(15, 20));5. Union types
Restricted valuests
type Exam = 'GCE' | 'HND' | 'BTS';
type Learner = {
name: string;
exam: Exam;
};
const learner: Learner = { name: 'Amina', exam: 'HND' };6. Narrowing makes unions useful
Narrow unknown shapests
function formatId(id: string | number) {
if (typeof id === 'number') {
return id.toFixed(0);
}
return id.toUpperCase();
}7. Interface versus type
| Tool | Great for |
|---|---|
| interface | Named object contracts and extension |
| type | Objects, unions, tuples, primitives and composition |
Interface examplets
interface Product {
id: string;
name: string;
price: number;
}
function label(product: Product) {
return `${product.name}: ${product.price} FCFA`;
}8. Generics: keep relationships between types
Generic helperts
function first<T>(items: T[]): T | undefined {
return items[0];
}
const firstScore = first([12, 14, 18]); // number | undefined
const firstName = first(['A', 'B', 'C']); // string | undefined9. Classes are available, but not mandatory
Small classts
class Wallet {
balance = 0;
deposit(amount: number) {
if (amount <= 0) throw new Error('amount must be positive');
this.balance += amount;
}
}
const wallet = new Wallet();
wallet.deposit(500);10. Compile and run
Compiler loopbash
npx tsc
node dist/index.js11. Mini-project: typed study planner
planner.tsts
type TaskStatus = 'todo' | 'done';
type StudyTask = {
id: string;
title: string;
subject: string;
status: TaskStatus;
};
const tasks: StudyTask[] = [];
function addTask(title: string, subject: string): StudyTask {
const task: StudyTask = {
id: crypto.randomUUID(),
title,
subject,
status: 'todo',
};
tasks.push(task);
return task;
}
function completeTask(id: string) {
const task = tasks.find((item) => item.id === id);
if (task) task.status = 'done';
}Authoritative next steps
RESEARCH TRAIL
Sources and further reading
Clarvo articles are independently written. These references let you inspect the original inspiration and primary or official sources used to deepen the guide.
- Source inspiration — Learn TypeScript in 5 minutesmedium.com
- TypeScript official documentationtypescriptlang.org
KEEP READING

