A user could express 2 * 5 + 1
as
Because TypeScript used to infer the type BasicCalculator
for each method in BasicCalculator
that returned this
, the type system would forget that it had whenever using a BasicCalculator
method.
This is no longer the case - TypeScript now infers this
to have a special type called this
whenever inside an instance method of a class.The type is written as so, and basically means “the type of the left side of the dot in a method call”.