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

The last line compiles. Why is this assignment-then-call accepted even though it can be unsound?

class Comparable { compareTo(other: this): number { return 0; } } class Money extends Comparable { amount = 0; compareTo(other: this): number { return this.amount - other.amount; } } const m: Comparable = new Money(); m.compareTo(new Comparable());