← Back to topic library
Dev MaxxingBeginnerTypeScript60 sec
Type inference
Type inference is TypeScript automatically determining a value's type from context, without requiring the type to be written explicitly every time.
Prerequisite: TypeScript type
What matters
This lets developers get type-checking benefits without annotating every single variable, since TypeScript can often figure out the type from how a value is assigned or used.
Example
Writing 'let count = 0;' lets TypeScript infer that 'count' is a number, without needing to write 'let count: number = 0;' explicitly.
Common misconception
Type inference does not mean TypeScript skips checking untyped code; it still enforces the type it inferred, even though you didn't write it out yourself.
Recall question
What does TypeScript use to infer a variable's type when none is explicitly written?
Keywords and related concepts
type inferenceTypeScriptstatic typingtypescript type