Quiz · 3 questions
🧙 Generics — Where TypeScript Becomes Itself
Generic functions, types, constraints, defaults, conditional types, infer
Level 0Curious
0 XP0/93 lessons0/23 achievements
0/100 XP to next level100 XP to go0% complete
Quiz
01What does
function first<T>(arr: T[]): T actually do at the type level?Hint
Compare with the same function written without generics — you'd lose the link between input and output types.
02What does
T extends U mean in a generic constraint?Hint
Try writing
function len<T extends { length: number }>(x: T) { return x.length } and then calling it with strings, arrays, and objects with length.03What is a conditional type?
Hint
Try
type IsString<T> = T extends string ? true : false and see what IsString<'hi'> and IsString<42> evaluate to.Comments 0
🔔 Reply notifications (sign in)Sign in — Please sign in to comment.
No comments yet — be the first.