Courses
TypeScript Intermediate: Types That Survive Real Projects
Check Yourself: Generics Without the Fog
Five scenario questions on type parameters, constraints and generic types. If you miss more than one, reread the lessons in this section.
Course content
Join this Course
Sign in to save your progress.
-
Generics Without the Fog
-
Generic Functions That Keep the Input Type
-
Generic Types for Lists, Results and Caches
-
-
-
Types That Transform Other Types
-
Utility Types: Partial, Pick, Omit and Record
-
Mapped Types You Can Actually Read
-
-
-
Working With Code You Didn't Write
-
@types Packages and When DefinitelyTyped Is Wrong
-
Typing fetch JSON Without Lying to Yourself
-
-
-
Classes and Modules in TypeScript
-
Classes With public, private and protected
-
Modules, Exports and Avoiding Circular Types
-
-
-
Strictness That Pays Off
-
unknown vs any and Safe Parsing
-
Discriminated Unions for API Responses That Vary
-
-
- Final Check: TypeScript Intermediate
1.
A helper is declared as function firstOf(items: any[]): any and returns items[0]. You call it with [19.5, 20, 7] and then call toUpperCase on the result. What does the compiler do, and what is the better declaration?
It accepts the call, and nothing can be done about it, because arrays always give back any.
It rejects the call, because any is not allowed in strict mode.
It accepts the call, because the result is any. A type parameter, written firstOf with T, items as an array of T and a return type of T or undefined, keeps the number type so the call is rejected.
It rejects the call, because numbers have no toUpperCase method.
2.
You write function longest with T extending an object type with a numeric length property, taking two parameters of type T and returning T. A teammate calls longest(10, 20). What happens?
3.
mapAll takes items as an array of T and a callback from T to U, and returns an array of U. You call mapAll with ["a", "bb", "ccc"] and a callback that returns s.length. What is the type of the result?
4.
You declare type Page with a type parameter T, holding an array of T and a total, and then write const users: Page = { items: [], total: 0 }. What does the compiler say?
5.
A teammate writes function logValue with a type parameter T, one parameter of type T, and a void return. You are asked to review it. What is the most useful comment?
It will not compile, because a generic function must return T.
T appears in only one place, so it links nothing to anything else. A plain unknown parameter says the same thing with less syntax.
It is fine, because every function should be generic where possible.
It should use any instead of T, so that it accepts every value.
About
Five scenario questions on type parameters, constraints and generic types. If you miss more than one, reread the lessons in this section.
- Duration
- 5 min
- Last update
- 10/12/2026
Was this helpful?
0
0
Comments (0)
Sign in to commentNo comments yet.