TypeScript -- Course Overview - Wyatt's Notes
What Is TypeScript
Section titled “What Is TypeScript”TypeScript is a statically typed programming language developed by Microsoft. It is a strict Syntactic superset of JavaScript: every valid JavaScript program is, by definition, a valid TypeScript program. TypeScript adds a compile-time type system that is erased during compilation, Producing standard JavaScript output.
The type system is structural, meaning type compatibility is determined by the shape of values Rather than by explicit inheritance relationships or nominal declarations. This design choice aligns With JavaScript”s own duck-typing semantics while providing compile-time guarantees that catch a Broad class of errors before runtime.
Relationship to JavaScript
Section titled “Relationship to JavaScript”TypeScript compiles to JavaScript via the tsc compiler. The compilation process performs two Tasks:
- Type checking — verifying that the program respects all declared types and constraints.
- Code emission — producing JavaScript output (ES3 through ESNext targets) with type annotations removed.
Because TypeScript is a superset, existing JavaScript codebases can be adopted incrementally. The Compiler’s strict flag can be enabled progressively, allowing teams to tighten type safety at Their own pace.
Key Language Features
Section titled “Key Language Features”| Feature | Description |
|---|---|
| Type system | Primitive types, object types, union/intersection types, generics, conditional types, mapped types, template literal types |
| Generics | Parametric polymorphism with constraints, variance, and type-level inference |
| Enums | Numeric enums, string enums, const enums, and union enum patterns |
| Decorators | Stage 3 proposal for class and member decoration (experimental in current TS releases) |
| Modules | ES module import/export, declaration merging, ambient modules, namespaces |
| Utility types | Built-in generic utilities: Partial``Required``Readonly``Pick``Omit``Record``Exclude``Extract``ReturnType``Parameters``NonNullable |
| Type narrowing | Discriminated unions, typeof``instanceof``in operator, user-defined type guards |
| Toolchain integration | tsconfig.jsonDeclaration files (.d.ts), @types/ packages, project references |
The Toolchain
Section titled “The Toolchain”Compiler (tsc)
Section titled “Compiler (tsc)”The TypeScript compiler reads .ts (and .tsx) source files and produces .js output. Its Behaviour is controlled by tsconfig.json at the project root. Key compiler options include:
strict— enables all strict type-checking options.target— the ECMAScript version for emitted JavaScript.module— the module system for emitted code (CommonJS, ESNext, etc.).moduleResolution— the strategy for resolving module imports (node``bundlerclassic).noEmit— type-check without producing output files.
Configuration (tsconfig.json)
Section titled “Configuration (tsconfig.json)”Every non-trivial TypeScript project requires a tsconfig.json. This file declares compiler Options, file inclusion/exclusion globs, and project references. Monorepo structures use project References (composite: true) to enable incremental builds across package boundaries.
Type Definitions (@types/ and .d.ts)
Section titled “Type Definitions (@types/ and .d.ts)”JavaScript libraries without built-in TypeScript support are described by declaration files (.d.ts). These are published to the @types/ scope on npm via DefinitelyTyped. TypeScript Automatically resolves @types/ packages from node_modules/@types/ when typeRoots is not Explicitly overridden.
Declaration Files
Section titled “Declaration Files”Declaration files describe the shape of existing JavaScript modules or global variables without Providing implementations. They use declare keywords for variables, functions, classes, and Modules. Ambient context declarations (e.g., declare global { ... }) extend existing global scope.
Assessment Structure
Section titled “Assessment Structure”This course is organised into the following modules, each with its own dedicated chapter:
- Types and Annotations — the type system, narrowing, assertions, inference rules.
- Functions — function types, overloading, callbacks,
thistyping. - Generics — parametric polymorphism, utility types, conditional types, mapped types.
- Classes — OOP with TypeScript, abstract classes, interfaces, decorators.
- Enums and Modules — enum patterns, ES modules, namespaces, declaration merging.
- Advanced Patterns — recursive types, branded types, builder patterns, variadic tuples.
- Tooling and Configuration —
tsconfig.jsonProject references, ESLint integration. - TypeScript with React — component typing, hooks, context, refs.
- Error Handling —
never``unknownAssert functions, Result types.
Each module contains rigorous definitions, compile-ready code examples, comparison tables, and Common-pitfall warnings. Cross-references between modules are provided where topics are Interdependent.
Intuition
Section titled “Intuition”TypeScript types are like blueprints for a building. The blueprint describes what the building should look like: how many rooms, what goes in each room, and how they connect. JavaScript is the actual building; TypeScript is the blueprint that ensures the building is constructed correctly.
The type checker in TypeScript is like a building inspector who reviews your blueprints before construction begins. If you try to put a bedroom where the blueprint says kitchen, the inspector catches the error before you pour any concrete. This catches bugs at design time rather than at runtime.
Common Pitfalls
Section titled “Common Pitfalls”Using
anyas a shortcut. It disables all type checking for a value and propagates unsoundness. Preferunknownwhen the type is genuinely unknown.Relying on type assertions (
as) instead of proper narrowing. Everyasbypasses the compiler’s verification and can introduce runtime errors that TypeScript was supposed to prevent.Forgetting that
interfacedeclarations merge whiletypealiases do not. Accidental merging can cause subtle bugs in large codebases where the same interface name is used across files.Over-indexing arrays without
noUncheckedIndexedAccess. By default,arr[0]has typeT, notT | undefined, which hides potential undefined values at runtime.
Study Strategy
Section titled “Study Strategy”- Enable
strictmode immediately. It catches the broadest class of errors and forces good habits from the start. - Learn the type system first, the toolchain second. Structural typing, generics, and conditional types are the core intellectual content.
- Read declaration files (
.d.ts) from@types/packages to see how real-world APIs are typed. - Practise type-level programming. Write your own utility types to internalise mapped types, conditional types, and inference.
- Use
tsconfigstrict flags. EnablestrictNullChecks,noUncheckedIndexedAccess, andexactOptionalPropertyTypesfor maximum safety. - Avoid type assertions (
as). Prefer type guards and narrowing. Everyasis a hole in the type system that the compiler cannot verify.
flowchart TD
A[Typescript] --> B[Key Concepts]
A --> C[Core Principles]
A --> D[Practical Applications]
B --> E[Fundamental definitions]
C --> F[Design patterns]
D --> G[Real-world usage]Summary
Section titled “Summary”The key principles covered in this topic are linked in the sub-pages above. Focus on understanding the definitions, applying the formulas or frameworks, and evaluating strengths and limitations of each approach.
Worked Examples
Section titled “Worked Examples”Worked examples demonstrating the application of key concepts are covered in the detailed sub-pages linked above.
Cross-References
Section titled “Cross-References”- Types and Annotations - How TypeScript’s type system builds on JavaScript’s dynamic typing
- Tooling and Configuration - How the TypeScript compiler and tsconfig.json configure the development workflow
- Functions - How TypeScript adds type safety to JavaScript’s function expressions and declarations