JavaScript can accept a call that looks reasonable but fails only when it runs. TypeScript adds compile-time type checking to JavaScript: it is a superset of the language, so ordinary JavaScript code is also TypeScript code. Its checker can flag mismatched arguments before a browser or Node.js encounters them. section 2.1 section 2.0
// Incorrect code! The time should come after the callback.
setTimeout(200, () => {
console.log("This will never run.");
});
The arguments to setTimeout are reversed. TypeScript can flag the call even though the code is valid JavaScript; the resulting behavior differs between browser and Node.js runtimes. section 2.1
Annotate a parameter when callers must supply a particular type: `const doubleNumber = (x: number) => x * 2;` makes `doubleNumber("abc")` a type error. On conversion to JavaScript, the annotation is removed; it does not insert a runtime check. This distinction matters when values arrive from code whose behavior you cannot assume. section 5.5.1 section 5.5
Function types offer a few practical choices:
- Annotate rest arguments as an array, such as `...remainingNumbers: number[]`. A default value can supply a parameter’s inferred type; `string | null` explicitly permits either type. section 5.5.1
- Let TypeScript infer a return type from possible returns, or declare one after the parameter list. An explicit return type can expose a missing branch—for example, a sign function that handles positive and negative numbers but forgets zero. section 5.5.2
Static checking does not replace JavaScript’s runtime behavior: implicit coercion still exists. Editors such as VS Code can display type information and errors while you work. TypeScript can also transpile syntax for a chosen ECMAScript target, but it does not supply missing runtime APIs through polyfills. section 2.1 section 1.3.1 section 1.1.3
Running TypeScript need not always involve a compilation wait. Node.js 22.6.0 and newer can strip types with `--experimental-strip-types`, but stripping does not run the type checker. That flag excludes enum and namespace syntax; TypeScript 5.8’s `erasableSyntaxOnly` option can enforce compatible syntax. Compilation remains useful for browsers and older runtimes. section 2.1.4





