Static typing makes assumptions about values explicit so the TypeScript compiler can report incompatible uses before the resulting JavaScript runs. TypeScript still compiles to JavaScript for a browser or Node.js; its type features constrain development without replacing the JavaScript runtime. section 7.2.1 section 1.1.1
Annotate a function
In src/index.ts, `function calculateTax(amount: number): number { return amount * 1.2; }` specifies both the accepted argument and the result. `calculateTax(12)` is accepted; passing `"Hello"` or `true` produces a compiler error because neither is a number. The colon introduces a type annotation, not a JavaScript runtime check. section 7.2.1
Annotations also apply to variables and class properties: `let price: number = 100` and `public id: number` state which values belong there. They are not required everywhere. From `let price = 100`, the compiler infers `number`; it can also follow the result of a calculation through later assignments. section 7.2.1 section 7.2.2
Catch a change in the result
If `calculateTax` returns `(amount * 1.2).toFixed(2)`, its inferred result becomes a string. A later `taxAmount / 2` then produces a compiler error. JavaScript could attempt to coerce that string during execution, but TypeScript flags the potentially problematic operation instead. section 7.2.2
Check an application boundary
A to-do collection can declare `addTodo(task: string): number`. Calling `collection.addTodo(todoItem)` with a `TodoItem` rather than task text produces TS2345: the argument is not assignable to `string`. Fix the call rather than weakening the parameter type merely to silence the error. section 2.2.5
Types can be combined with unions and narrowed with guards; `any`, `unknown`, and `never` address different cases where ordinary types are insufficient. Compiler settings also matter: `strictNullChecks` changes whether `null` and `undefined` are accepted for other types. Apply annotations where they clarify a contract, and let inference handle straightforward values. section 7.8 section 7.2.2











