tezvyn:

What is the polymorphic this type in TypeScript?

Source: typescriptlang.orgadvanced

This tests polymorphic this for type-safe fluent APIs. A strong answer defines this as the current instance type, implements CSSBuilder methods that return this for chaining, and notes subclass preservation.

This tests TypeScript's polymorphic this for preserving exact instance types through inheritance in fluent builders. A strong answer explains that this represents the current instance type, not the base class; demonstrates CSSBuilder methods like setColor and setMargin returning this for chaining; and notes that subclasses inherit correctly typed methods without extra generics. A red flag is typing the return as the base class, which collapses the type and strips subclass properties.

Read the original → typescriptlang.org

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

What is the polymorphic this type in TypeScript? · Tezvyn