JavaScript can let a type mistake survive until the code runs. Type checking examines code before execution to find operations and arguments that do not fit their expected types. TypeScript adds this check to JavaScript code, so an error can surface while you write or compile it rather than as a runtime surprise. section 2.1 section 1.3.1
A string where a number is expected
Given `const addOne = (x: number) => x + 1`, TypeScript reports an error for `addOne("10")`. Without that check, JavaScript’s coercion would produce the string `"101"`. Checking does not remove coercion from JavaScript: `1 + "2"` still produces `"12"`. It helps by identifying that result as a string when a later use expects something else. section 1.3.1 section 2.1
$ npx tsc
timeout.ts:1:12 - error TS2345: Argument of type 'number' is not assignable to parameter of type 'TimerHandler'.
1 setTimeout(200, () => {
~~~
Found 1 error in timeout.ts:1
The compiler output pinpoints a second argument mistake: `setTimeout` expects a callback first, but receives the number `200`. Ordinary JavaScript accepts the syntax; the TypeScript checker reports the mismatch before the code runs. section 2.1 section 2.1.1
A practical checking workflow separates finding errors from running code:
- Install TypeScript as a development dependency, create a starter `tsconfig.json` with `npx tsc --init`, then run `npx tsc` to check the project’s `.ts` files. The configuration controls matters such as checking strictness and whether JavaScript is emitted. section 2.1.1
- Do not assume a reported error prevents output: in the shown setup, `tsc` still emits JavaScript after finding the `setTimeout` error. section 2.1.1
- Use editor feedback for errors and type information while working, and run full-project checks in continuous integration. A runtime that directly runs TypeScript by stripping types does not necessarily check them; keep checking as a separate step. section 2.1.4






