TypeScript challenges

Practice problem statements with input format, output format, constraints and solutions.

beginner

TypeScript Introduction challenge

Build a small solution that uses TypeScript Introduction in TypeScript and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

interface Order {
  id: number;
  total: number;
  status: "paid" | "pending";
  customer: string;
}

const order: Order = { id: 42, total: 50, status: "paid", customer: "Asha" };
console.log(order);

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core typescript introduction pattern before polishing the final output.

Solution

interface Order {
  id: number;
  total: number;
  status: "paid" | "pending";
  customer: string;
}

const order: Order = { id: 42, total: 50, status: "paid", customer: "Asha" };
console.log(order);
beginner

TypeScript Setup challenge

Build a small solution that uses TypeScript Setup in TypeScript and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

interface Order {
  id: number;
  total: number;
  status: "paid" | "pending";
  customer: string;
}

const order: Order = { id: 42, total: 51, status: "paid", customer: "Asha" };
console.log(order);

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core typescript setup pattern before polishing the final output.

Solution

interface Order {
  id: number;
  total: number;
  status: "paid" | "pending";
  customer: string;
}

const order: Order = { id: 42, total: 51, status: "paid", customer: "Asha" };
console.log(order);
beginner

Basic Types challenge

Build a small solution that uses Basic Types in TypeScript and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

interface Order {
  id: number;
  total: number;
  status: "paid" | "pending";
  customer: string;
}

const order: Order = { id: 42, total: 52, status: "paid", customer: "Asha" };
console.log(order);

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core basic types pattern before polishing the final output.

Solution

interface Order {
  id: number;
  total: number;
  status: "paid" | "pending";
  customer: string;
}

const order: Order = { id: 42, total: 52, status: "paid", customer: "Asha" };
console.log(order);
beginner

Arrays and Tuples challenge

Build a small solution that uses Arrays and Tuples in TypeScript and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

const lesson: string = "Arrays and Tuples";
const duration: number = 53;
console.log(`Learning ${lesson} in ${duration} minutes.`);

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core arrays and tuples pattern before polishing the final output.

Solution

const lesson: string = "Arrays and Tuples solution";
const duration: number = 53;
console.log(`Learning ${lesson} in ${duration} minutes.`);
beginner

Enums challenge

Build a small solution that uses Enums in TypeScript and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

const lesson: string = "Enums";
const duration: number = 54;
console.log(`Learning ${lesson} in ${duration} minutes.`);

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core enums pattern before polishing the final output.

Solution

const lesson: string = "Enums solution";
const duration: number = 54;
console.log(`Learning ${lesson} in ${duration} minutes.`);
beginner

Interfaces challenge

Build a small solution that uses Interfaces in TypeScript and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

interface Order {
  id: number;
  total: number;
  status: "paid" | "pending";
  customer: string;
}

const order: Order = { id: 42, total: 55, status: "paid", customer: "Asha" };
console.log(order);

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core interfaces pattern before polishing the final output.

Solution

interface Order {
  id: number;
  total: number;
  status: "paid" | "pending";
  customer: string;
}

const order: Order = { id: 42, total: 55, status: "paid", customer: "Asha" };
console.log(order);
beginner

Type Aliases challenge

Build a small solution that uses Type Aliases in TypeScript and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

interface Order {
  id: number;
  total: number;
  status: "paid" | "pending";
  customer: string;
}

const order: Order = { id: 42, total: 56, status: "paid", customer: "Asha" };
console.log(order);

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core type aliases pattern before polishing the final output.

Solution

interface Order {
  id: number;
  total: number;
  status: "paid" | "pending";
  customer: string;
}

const order: Order = { id: 42, total: 56, status: "paid", customer: "Asha" };
console.log(order);
beginner

Union and Intersection Types challenge

Build a small solution that uses Union and Intersection Types in TypeScript and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

interface Order {
  id: number;
  total: number;
  status: "paid" | "pending";
  customer: string;
}

const order: Order = { id: 42, total: 57, status: "paid", customer: "Asha" };
console.log(order);

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core union and intersection types pattern before polishing the final output.

Solution

interface Order {
  id: number;
  total: number;
  status: "paid" | "pending";
  customer: string;
}

const order: Order = { id: 42, total: 57, status: "paid", customer: "Asha" };
console.log(order);
beginner

Functions in TS challenge

Build a small solution that uses Functions in TS in TypeScript and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

const lesson: string = "Functions in TS";
const duration: number = 58;
console.log(`Learning ${lesson} in ${duration} minutes.`);

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core functions in ts pattern before polishing the final output.

Solution

const lesson: string = "Functions in TS solution";
const duration: number = 58;
console.log(`Learning ${lesson} in ${duration} minutes.`);
beginner

Classes in TS challenge

Build a small solution that uses Classes in TS in TypeScript and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

const lesson: string = "Classes in TS";
const duration: number = 59;
console.log(`Learning ${lesson} in ${duration} minutes.`);

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core classes in ts pattern before polishing the final output.

Solution

const lesson: string = "Classes in TS solution";
const duration: number = 59;
console.log(`Learning ${lesson} in ${duration} minutes.`);