How to use TypeScript with React... But should you?
Based on Fireship's video on YouTube. If you like this content, support the original creators by watching, liking and subscribing to their content.
TypeScript is a superset of JavaScript, so React code can remain familiar while gaining optional type-checking features.
Briefing
TypeScript’s biggest practical value in React isn’t that it changes how components run—it’s that it adds a compile-time type system that catches many common mistakes before the app ever ships. The core workflow stays familiar: TypeScript is a superset of JavaScript, so the code you write looks like JavaScript, but a compiler (configured via tsconfig) transpiles it into browser-ready JavaScript. That means teams can keep modern syntax and features while still targeting older environments, much like Babel already does in JavaScript-only React setups.
The transcript draws a clear line between what TypeScript can prevent and what it can’t. On the “catch bugs early” side, it highlights a typical runtime failure: starting with an empty object, then later accessing a deeply nested property that doesn’t exist. In plain JavaScript, that can slip through and crash in production. With TypeScript, the mismatch can be flagged during development—described as a “precog” that warns before the app runs. But the benefits aren’t a replacement for testing; TypeScript can’t guarantee correctness for logic errors (“batlogic”) or cover every scenario, so it complements rather than substitutes for test-driven development.
Where TypeScript becomes most tangible is its type system for React components and props. React components in TypeScript can be typed using FC (function component), which gives the compiler a concrete shape for the component. Props then stop being an unstructured “any” and become an explicit contract. The transcript walks through defining a props interface (e.g., cool props with a number and a string, with options for required vs optional fields). Once that interface is wired into the component type, editors provide autocomplete and enforce that required props are present—turning many “silly” integration mistakes into compile-time errors.
That comes with trade-offs. Adding types introduces boilerplate and friction, especially at the start, and the transcript notes that developers can bypass the system entirely by using any, which removes the safety net. There’s also a configuration cost: tsconfig can include strictness settings (with strict mode recommended) and a Target that controls which JavaScript version TypeScript outputs. The payoff is smoother refactoring and safer collaboration, particularly when multiple developers touch the same code.
Finally, the transcript frames the decision as a balance of confidence versus effort. It references survey claims attributed to Microsoft and Airbnb about the percentage of bugs TypeScript catches, then contrasts that with the real-world alternatives: manual documentation versus editor-driven intellisense, faster initial coding versus less chaotic refactoring later. The takeaway is that TypeScript’s value in React comes from turning implicit assumptions—about data shapes, props, and state—into enforceable contracts during development, while still requiring tests for full correctness.
Cornell Notes
TypeScript is a superset of JavaScript, so React code can look familiar while gaining a compile-time type system. A compiler configured by tsconfig transpiles TypeScript into browser-ready JavaScript, making modern syntax usable across environments. In React, typing components with FC and defining props via interfaces replaces vague any props with explicit contracts, enabling autocomplete and catching missing/incorrect props early. TypeScript can prevent certain runtime crashes (like accessing nested properties on an empty object), but it doesn’t replace testing for logic errors. The main trade-off is added boilerplate and stricter development workflow, which can be mitigated by using inference where possible and enabling strict mode for long-term maintainability.
How can TypeScript be “optional” to learn if it’s not a new language?
Why does tsconfig matter in a React + TypeScript project?
What kind of bug does TypeScript catch that JavaScript often ships to production?
How do FC and props interfaces change React development?
What are the main downsides or escape hatches of TypeScript?
Does TypeScript replace testing?
Review Questions
- What does it mean that TypeScript is a superset of JavaScript, and what role does the compiler play for browser execution?
- How do strict mode and Target in tsconfig affect development and compatibility?
- In what ways do FC and props interfaces improve correctness and developer experience in React?
Key Points
- 1
TypeScript is a superset of JavaScript, so React code can remain familiar while gaining optional type-checking features.
- 2
A TypeScript compiler transpiles code into browser-ready JavaScript, with tsconfig controlling strictness and output Target.
- 3
Enabling strict mode (strict: True) increases early friction but improves refactoring safety and team collaboration.
- 4
TypeScript can catch certain runtime crash patterns during development, such as invalid nested property access on incorrectly typed values.
- 5
React props become safer when typed explicitly (e.g., using FC and props interfaces) instead of defaulting to any.
- 6
TypeScript adds boilerplate and can be undermined by opting out with any, so teams must use types intentionally.
- 7
Type safety complements testing; it doesn’t replace tests for logic errors.