← All Exercises

Interface Definition Basics

basictypescript~10min

Background

Interfaces are the primary way to define object shapes in TypeScript, enabling structural typing and code documentation.

Problem

Create a User interface with id (number), name (string), email (string), and optional age (number), then write a function that returns a summary string.

Input

An object conforming to the User interface.

Output

A summary string containing user information.

Sample tests

Sample 1

Input: {id:1, name:"Alice", email:"[email protected]"}
Expected: "User #1: Alice ([email protected])"

Your solution

Learning objective

Learn interface definitions with required and optional properties in TypeScript.