Lesson 2 of 9
Lesson 02 — TypeScript basics for QA data
Title: Variables, arrays, and object literals with types
Description: Attach explicit types to the values you move through tests: credentials, IDs, flags. TypeScript catches mistakes before runtime.
Why it matters for QA: Fixtures and API mocks mirror production payloads. Typed shapes stop "undefinded" typos and wrong property names from slipping into suites.
1. Primitive variables
let name: string = "QA Engineer";
let age: number = 25;
let isActive: boolean = true;
Prefer const when you do not reassign:
const environment = "staging";
2. Arrays
let users: string[] = ["Anna", "John"];
let ids: Array<number> = [1, 2, 3];
Mixed arrays without unions need explicit annotation:
type Cell = string | number;
const row: Cell[] = ["login", 200];
3. Objects with inline shapes
let user: { name: string; age: number } = {
name: "Anna",
age: 30,
};
If you forget age, the checker fails immediately — exactly what you want before committing fixtures.
4. Practice: credential sketch
Implement typed variables for:
let email: string;
let password: string;
let role: string;
email = "learner@example.com";
password = "CorrectHorseBatteryStaple!";
role = "tester";
console.log({ email, role });
Extend with readonly intent mentally: credentials often flow one direction into helpers — immutability habits start here.
5. Think like automation data
When modeling UI state before interfaces:
const checkoutTotals = {
subtotal: 49.99,
taxRate: 0.07,
};
let cartEmpty: boolean = false;
6. Stretch goal
Define two objects representing bug reproduction inputs (steps, expected, actual) with inline types. Log them using JSON.stringify.