TypeScript · TypeScript Generics Explained: Functions, Interfaces and Constraints
Question 1 of 5
What type does TypeScript infer for s?
function firstOr<T>(items: T[], fallback: T): T {
return items.length > 0 ? items[0] : fallback;
}
const s = firstOr(["a"], "none");Tip: press 1-4 to answer, Enter to continue. Finish the quiz to bank your XP.