Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardTypeScriptpolymorphic thisSingle-choice MCQ

A method uses a polymorphic `this` return type to enable a fluent builder. Given the chained call, what is the inferred type at the marked position, and why?

class Box<T> { protected value!: T; set(v: T): this { this.value = v; return this; } } class NamedBox<T> extends Box<T> { name = ""; rename(n: string): this { this.name = n; return this; } } const b = new NamedBox<number>().set(1).rename("x"); // ^? what is the type of `b`?