Inference Does Most of the Work

You annotate far less than people expect. TypeScript works out the type from the value, and annotating what it already knows is noise that will eventually rot and start lying.

Annotate the boundaries: function parameters, return types where they are not obvious, and containers that start empty.

Try it

Change const name to let name, then assign a different string. With const the type is the literal "Amara"; with let it widens to string.

loading editor…

checking…

count was never annotated and is still checked. Inference is not a weaker form of typing; it is the same typing without the ceremony.

const infers narrower than let. const s = "ready" has the type "ready", not string. let s = "ready" has the type string.

That difference looks pedantic and becomes load-bearing in module 6, where literal types are what make a union tell its branches apart.

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: The Types You Use Daily, and any →
← Back