← All Exercises

Template Literal Type Inference

advancedtypescript~35min

Background

Template literal types with infer enable type-level string parsing for routes, event names, and configuration keys.

Problem

Create a type that extracts the route parameter name from a path pattern like "/users/:id" using template literal inference.

Input

A string pattern containing a parameter placeholder.

Output

The extracted parameter name, or never if no parameter exists.

Sample tests

Sample 1

Input: "/users/:id"
Expected: "id"

Your solution

Learning objective

Learn template literal type inference with infer for type-level string parsing.