TypeScript Beginner Exercises with Solutions

Learn how TypeScript describes the shape of data. These three beginner exercises cover typed function parameters, an interface for array items and a small generic helper.

Know JavaScript functions, objects and arrays. The lessons introduce type annotations, interfaces and generic type parameters step by step.

What you will practise

Annotate parameters and results

Describe an object with a type and return a formatted string from a typed function.

Describe array items with an interface

Filter an array of User objects and return a string array of names.

Keep types linked with generics

Write first<T>() so that the result type follows the array you pass in.

3 exercises to try

How to use these exercises

Read the types before you write the body. Predict the printed result, then run your attempt. Afterwards change an annotation on purpose and check the error in a full TypeScript project or editor.

Runtime and progress

The quick playground transpiles TypeScript and runs the JavaScript output. It does not report every static type error, so use a full TypeScript project to check complete type safety.

Completion is self-reported. There is no automated grading, and progress is saved only on this device.

Browse every practice topic