Lesson 50 of 50TypeScript
Wrap-Up: JavaScript & TypeScript
Tie the whole track together: one realistic feature built in JavaScript and TypeScript from the form to the network and back, a mixed review, and where to go next.
You started this track with the story of a language written in ten days and a single let. Since then you have learned how JavaScript really behaves, driven a page with the DOM, tamed async code, used the tools teams ship with, and added a type system on top that you can trust across the network. On the job none of this arrives one lesson at a time. This lesson lines the units up once more and then uses them together on one piece of work.
The path you took
Unit 1
JavaScript basics
Values, control flow, functions, arrays, objects and equality gave you the everyday language, ready to be understood more deeply.
Unit 2
JavaScript in depth
Closures, this, classes, Maps, iterators, errors, modules, Node and Vitest explained why code behaves as it does and how to prove it works.
Unit 3
JavaScript in the browser
The DOM, events and forms put that language on a real page, and the to-do project showed state, events and render working as one loop.
Unit 4
Async JavaScript
The event loop, promises, async/await and API patterns let that page talk to servers without freezing or losing errors.
Unit 5
JavaScript at work
Package managers, monorepos, security and performance turned working code into code a team can ship safely.
Unit 6
TypeScript
Types, narrowing, generics and toolchain setup let the compiler guard all of it, schema validation kept those types honest at the edges, and Project: A Typed Expense Tracker used them together in one typed core.
How it fits together
The ticket: "Add a job search box to the careers page. Results should update as people type, show a clear loading and error state, and remember the last search. The API is a Python service with an OpenAPI spec." Here is how the track shows up, in the order you would really work.
Setting up. The careers page lives in a pnpm workspace, so you add the feature to the right package and let the task graph from Monorepos and Workspaces rebuild only what changed. You install nothing new without checking it, following Package Managers, Linters and Bundlers, because a small search box does not justify a large dependency. The tsconfig.json already has strict on, as Modules and tsconfig recommended, and the dev server strips types while tsc --noEmit checks them in CI, the split from The TypeScript Toolchain in 2026.
Getting the contract. The backend is not TypeScript, so you generate types from its OpenAPI spec, as End-to-End Type Safety showed. CI regenerates them on every change and fails on drift, so a renamed field breaks the build, not the page.
Modelling the state. Instead of three booleans that can contradict each other, the search state is a discriminated union from Unions and Narrowing: idle, loading, success or error. A switch with a never check means a new state cannot be added without handling it. A Job is an interface from Interfaces and Type Aliases, and Pick from Utility Types gives you the smaller shape the result list needs.
Wiring the form. You listen for submit, not click, and read the field with FormData, as Forms in JavaScript taught. Results render into a list with one delegated listener on the parent, from DOM Events. Job titles come from the server, so they go in with textContent, never innerHTML, the rule from The DOM and Web Security for JavaScript Developers.
Calling the API. Typing fires a request per key, so you debounce it, and when a new query starts you abort the old one with AbortController, both from Async Patterns. The call itself uses fetch with a timeout from Async/Await and fetch, and builds its query with URLSearchParams from Working with APIs. You know why a resolved promise logs before a timer, because you met that order in The Event Loop, and it explains why your loading state paints when it does.
Trusting nothing at the edge. The generated types describe what the API promises, not what arrives. So the response is unknown until a check says otherwise, the idea from Type Safety in Practice. Here is that boundary in miniature, runnable as is:
Press Run (⌘ Enter) to see what happens.The second body has a numeric id. A cast with as Job[] would have let it through and broken something later. The type predicate rejects it at the door, and the error becomes a state the user can see. In the real feature a Zod schema does the same job with less code.
Showing the results. Each job has a posting time in UTC. You format it with Intl.RelativeTimeFormat in the reader's locale, as Dates, Time Zones and Intl taught, and you never parse a loose date string with new Date. Sorting by salary uses a compare function, because the default sort compares strings, the trap from Arrays and Objects.
Remembering the search. The last query goes into localStorage with JSON.stringify, and comes back through JSON.parse inside a try, since storage can be empty, full or edited by hand (JSON and Browser Storage). No token or personal data goes there.
Proving it works. Vitest tests from Testing JavaScript and TypeScript with Vitest cover the parser with a table of good and bad bodies, and use fake timers to check that five quick keystrokes send one request. A mocked fetch returns a failure so the error state is tested too.
Keeping it fast. On a slow phone, typing feels sticky. A performance trace from Performance and Memory in the Browser shows a long task re-rendering every result on each response. Rendering only the changed list fixes it, and removing the listener when the panel closes stops a slow leak.
Notice that no lesson worked alone. The discriminated union made the tests simple, the abort logic made the union honest, and the boundary check turned a backend bug into a visible error instead of a broken page. That is JavaScript and TypeScript at work.
Check yourself
What does this print?
console.log("a");
setTimeout(() => console.log("b"), 0);
Promise.resolve().then(() => console.log("c"));
console.log("d");What does this print?
const limit = 0; console.log(limit || 20, limit ?? 20);
const jobs = (await res.json()) as Job[]. What does TypeScript check at runtime?Match each job to the tool you would reach for.
Put the steps of handling a search form submit in a sensible order.
- Tap the steps below in the right order.
[10, 9, 1] (in thousands) show in the wrong order after salaries.sort(). Why?What you can do now
- Read and write modern JavaScript, and explain closures,
this, prototypes and the event loop when code surprises you. - Build an interactive page with the DOM, events and forms that is safe from XSS and accessible to keyboard and screen reader users.
- Call APIs with
fetch, handle loading, error and empty states, cancel stale requests and retry sensibly. - Set up a project with npm or pnpm, a linter, a strict
tsconfigand Vitest tests that do not depend on the network or the clock. - Type real code with unions, narrowing, generics and utility types, and validate data at every boundary instead of casting it.
- Spot common security and performance problems in a frontend code review.
That is a solid junior level in the language and its tooling, with some mid-level type system skill. What you do not have yet is depth in a framework or a large existing codebase. That comes from the next courses and from real projects.
Mistakes that still catch people
- Trusting a type you never checked.
as,anyandres.json()let wrong data in silently. Revisit Type Safety in Practice and End-to-End Type Safety. - Mutating what you meant to copy. Spread is shallow, and
sortchanges the original array. Revisit Destructuring, Spread and Safe Access and Array Methods in Depth. - Forgetting to await, or awaiting in a loop. Floating promises lose errors, and sequential awaits make independent calls slow. Revisit Async/Await and fetch and Typing Functions.
- Losing
thisin a callback. Passingobj.methodto a listener detaches it fromobj. Revisit Scope, Closures and this. - Putting server text into
innerHTML. It turns data into code. Revisit The DOM and Web Security for JavaScript Developers. - Parsing dates from loose strings.
new Date("2026-03-01")andnew Date("03/01/2026")do not mean the same thing. Revisit Dates, Time Zones and Intl.
Where to go next
The natural next course is React: it takes the state, events and render loop from the to-do project and handles the rendering for you, and it is written in the TypeScript you now know. After that, Next.js adds routing, server rendering and Server Actions, where the end-to-end typing from the last unit does real work. If interviews are close, Algorithms & Patterns lets you drill problem patterns in the language you will most likely be asked to use.
Real practice matters as much as the next course:
- Build a small app that calls a real API. A search or dashboard page with typed state, a schema at the boundary, tests and a deploy.
- Convert a JavaScript project to strict TypeScript. Turn on
checkJsor rename files one at a time and fix what the compiler finds. You will learn more about types in a week than in a month of reading. - Read the official docs. MDN for the language and browser APIs, and the TypeScript Handbook at typescriptlang.org, will answer questions for years.
- Build one in your browser. The Project Lab walks you through real projects step by step. Snack match is a good one to retype with TypeScript types once it works.
- event loop
- The mechanism that runs synchronous code, then drains microtasks such as promise callbacks, then takes the next task such as a timer, one at a time.
- type erasure
- TypeScript removes all types when it compiles to JavaScript, so nothing about them is checked at runtime.
- trust boundary
- Any point where data enters from outside your code, like a network response, form, storage or env var, and must be checked.
- discriminated union
- A union of object types that share a literal field, such as
status, which TypeScript uses to narrow to one case. - narrowing
- Refining a broad type to a specific one with checks such as
typeof,in, equality or a type predicate. - event delegation
- Handling events for many child elements with one listener on a parent, using
event.targetto find the source. - lockfile
- A file recording the exact version of every installed package, so every machine and CI run installs the same tree.