← All Exercises

Generic Type Inference

intermediatetypescript~15min

Background

Generics enable writing reusable type-safe functions where the type is determined by the caller, not the author.

Problem

Create a generic function that wraps a value in an object with a value property, and another that creates a typed pair, both with inferred generic types.

Input

Any value of any type.

Output

An object wrapping the value with proper inferred types.

Sample tests

Sample 1

Input: 42
Expected: {value: 42}

Your solution

Learning objective

Understand generic type inference and how TypeScript deduces type parameters automatically.