Lesson 5 of 9

Lesson 05 — Advanced types QA relies on

Title: Enums, void, unknown, never — and why any is risky

Description: Pick the right tool when modeling statuses, logging helpers, uncertain JSON, or impossible branches TypeScript must narrow away.

Why it matters for QA: Reports (Passed, Skipped), flaky classifications, API probes — expressive types communicate intent inside suites.


Type cheat sheet

Type keywordMeaningQA usage
enumNamed numeric/string membersRoles, pipeline statuses
voidNo meaningful returnUtility logging wrappers
anyTurns checker offAvoid except migration spikes
unknownSafe “I will narrow this”Raw API bodies before guards
neverNo reachable valueExhaustive switch helpers

1. enum for fixed sets

typescripttypescript
enum TestStatus {
  Passed,
  Failed,
  Skipped,
}

enum Role {
  Admin,
  User,
  Guest,
}

const lastRun: TestStatus = TestStatus.Passed;

String enums are common in web services — learn both styles as you read existing codebases.


2. void for side-effect utilities

typescripttypescript
function logStep(message: string): void {
  console.log(`[STEP] ${message}`);
}

3. Avoid any

typescripttypescript
// Discouraged — everything compiles, nothing is trustworthy.
let data: any = "hello";
data = 123;

During greenfield QA work prefer unknown + guards or explicit DTO interfaces.


4. unknown stays safe until narrowed

typescripttypescript
let response: unknown = "from network";

if (typeof response === "string") {
  console.log(response.toUpperCase());
}

5. never for deliberate throws

typescripttypescript
function throwError(message: string): never {
  throw new Error(`${JSON.stringify(message)}`);
}

6. Practice

  1. Replace any with unknown

Instead of using any for a fixture parser, use unknown. Then:

  • check the type using typeof
  • check arrays using Array.isArray()

👉 This makes the code safer, because you must validate data before using it.