Type Inference

When there is no explicit type annotation then TypeScript will infer the type for you:

1
2
/** TypeScript infers `number` because "x" is initialized with a number and can be reassigned. */
let x = 10;
1
2
/** TypeScript infers `10` because "x" is a constant and cannot be reassigned. */
const x = 10;
1
2
/** TypeScript infers an array of `(string | number)` value types. */
const x = [10, '11'];