The TypeScript compiler checks whether code follows its type rules and can emit JavaScript. Catching a mismatched argument before runtime helps avoid surprising behavior in JavaScript. section 1.3.1
const addOne = (x: number) => x + 1; #A
addOne("10"); #B
The annotated parameter expects a number, so passing a string produces a compile-time error. section 1.3.1
Configure the compiler through tsconfig.json, which specifies:
- Which TypeScript files to compile and which external types to include. section 2.1.1
- How strictly to check types and whether to emit JavaScript; if emitting, which ECMAScript version to target. section 2.1.1
- Run `npx tsc --init` to create a starter configuration, then `npx tsc` to check and compile the project. Type errors do not necessarily prevent JavaScript output. section 2.1.1
Type annotations are removed from emitted JavaScript rather than checked at runtime. The compiler can also transform syntax for a chosen ECMAScript target, but it does not add polyfills for missing runtime features. section 5.5.1 section 1.1.3



