Find: Missing Type Parameter
Find the Mistake Medium
Question
This code has a type error. Find the mistake:
Code
function pair<T>(a: T, b: T): [T, T] {
return [a, b];
}
const result = pair<string>("hello", 42);
Hint
Both arguments must match the type parameter T.
Explanation
The function pair<T> requires both arguments to be the same type T. By explicitly specifying pair<string>, both arguments must be strings. But 42 is a number. TypeScript errors: Argument of type 'number' is not assignable to parameter of type 'string'. Fix: use pair<string | number>("hello", 42) or pair("hello", "42").
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.