contextual typing

Type inference that flows from where a value is used, such as giving a callback's parameters the types the calling function expects.

In more detail

In items.filter((item) => item.price > 10), item gets the element type of items without any annotation. Event handlers passed to addEventListener likewise receive the right event type. This is why callbacks rarely need written types.

Related terms

Taught in

References