TypeScript is a typed superset of JavaScript that compiles to plain JS — it catches type errors at compile time rather than runtime, enables intelligent IDE tooling (autocomplete, refactoring, go-to-definition), and has become the industry standard for production JavaScript applications.
All JavaScript is valid TypeScript — TypeScript adds type annotations, interfaces, and generics that are completely erased at compile time.
Type errors are caught during development, not at runtime — the compiler reports mismatches, missing properties, and incorrect arguments before code ships.
TypeScript infers types from values and context — explicit annotations are only needed where inference falls short (function parameters, empty arrays).
The strict flag enables strictNullChecks, noImplicitAny, and other checks that catch significantly more bugs — always use it in production.
All types are erased during compilation — the output JavaScript is identical to hand-written JS with no runtime overhead or dependencies.
TypeScript adds a static type system to JavaScript. Every valid JavaScript program is already valid TypeScript — TypeScript is a strict superset that adds optional type annotations, interfaces, generics, and other features that are erased at compile time, producing plain JavaScript.
JavaScript is dynamically typed — a variable can hold any value, and type errors only surface at runtime. This works fine for small scripts but becomes painful at scale: renaming a property might break 50 callsites that the developer can't find, a function might receive undefined instead of a string, or an API response might have a different shape than expected.
TypeScript's type system catches these errors during development, before the code runs. The compiler analyzes your code and reports type mismatches, missing properties, incorrect function arguments, and unreachable code.
TypeScript code (.ts/.tsx files) goes through the TypeScript compiler (tsc) or a bundler with TypeScript support (esbuild, SWC, Vite). The compiler does two things:
Importantly, TypeScript types have zero runtime cost — they're completely erased during compilation. The output JavaScript is identical to what you'd write by hand, just without the type annotations. This means TypeScript doesn't change JavaScript's runtime behavior.
You don't need to annotate every variable. TypeScript infers types from context:
let count = 0; // inferred as number
const name = 'Alice'; // inferred as literal type 'Alice'
const items = [1, 2, 3]; // inferred as number[]Explicit annotations are needed when TypeScript can't infer (function parameters, empty arrays, complex return types) or when you want to be more specific than the inference.
TypeScript has a strict compiler flag that enables a bundle of stricter checks: strictNullChecks (null/undefined are separate types), noImplicitAny (must annotate when inference fails), strictFunctionTypes (contravariant parameter checking), and others. Production projects should always use strict mode — it catches significantly more bugs.
Without strictNullChecks, every type implicitly includes null and undefined, which defeats much of TypeScript's safety. With it enabled, you must explicitly handle nullable values: string | null or optional chaining obj?.property.
tsconfig.json configures the TypeScript compiler: which files to include, what JavaScript version to target, which strict checks to enable, module resolution strategy, and path aliases. Key settings:
target: JavaScript version to emit (ES2020, ES2022, ESNext)module: Module system (ESNext, CommonJS, NodeNext)strict: Enable all strict type checksmoduleResolution: How imports are resolved (bundler, node16, nodenext)paths: Path aliases for cleaner importsTypeScript won the typed JavaScript competition. Flow (by Meta) had similar goals but lost momentum — most projects have migrated to TypeScript. JSDoc type annotations (@type, @param) provide types in JavaScript comments without a build step, useful for small projects or libraries that want to ship without compilation.
TypeScript is a typed superset of JavaScript that compiles to plain JS with zero runtime overhead. Types are erased during compilation — they exist only for developer tooling and compile-time checking. Always use strict mode in production. Type inference handles most annotations automatically; explicit types are needed for function parameters and complex cases.
Fun Fact
TypeScript was created by Anders Hejlsberg at Microsoft — the same person who designed C#, Delphi, and Turbo Pascal. He started the project in 2010, and TypeScript was publicly released in 2012. By 2023, TypeScript overtook JavaScript as the most commonly used language in new GitHub repositories.