Free tools Windows power users keep installed
One-click scans. No signup required.
You can learn TypeScript and React together: start with a framework that supports TypeScript, or add TypeScript to an existing app. For your first components, focus on a few essentials: put JSX in .tsx files, define the props a component accepts, and let React’s types help check Hooks and event handlers. TypeScript checks your code during development; it does not validate external data at runtime.
Choose a setup path
React’s documentation says that production-grade React frameworks support TypeScript and recommends following the setup instructions for your chosen framework. That is the clearest route for a new project because the framework’s configuration determines how TypeScript and JSX are handled. See React’s TypeScript guide for its framework guidance.
As an Amazon Associate I earn from qualifying purchases.
For an existing React project, React’s guide shows installing the React type definitions as development dependencies:
npm install --save-dev @types/react @types/react-dom
Use that command in the context of the project’s existing toolchain; it does not replace any framework-specific TypeScript setup.
#1 Best Overall
Put JSX in .tsx files and configure JSX handling
Every file that contains JSX needs the .tsx extension. TypeScript also needs a JSX option in tsconfig.json. For a React web application, React’s guide says the TypeScript lib setting should include dom. The appropriate JSX mode depends on the build pipeline: preserve leaves JSX for another transform, react emits React.createElement calls, and react-jsx emits calls to the automatic JSX runtime. TypeScript also documents react-jsxdev and react-native modes.
React says preserve is sufficient for most applications and advises libraries to consult the JSX documentation. Do not choose an emit mode by habit: use the option required by your framework or the tool that transforms JSX. The full set of options and their behavior is in the TypeScript JSX handbook.
Rank #2
- TypeScript implements a superset of syntax for strictly typed development, facilitating deep static analysis and enhanced development environment integration. The compiler translates source into standard script formats, ensuring parity across any runtime.
- TypeScript is ideal for front-end developers, full-stack engineers, and software architects who build large-scale web applications. It serves those looking to improve code excellence, reduce bugs through static checking, and maintain complex projects more.
- Lightweight, Classic fit, Double-needle sleeve and bottom hem
Type a component’s props
A prop is an input passed to a component. For a small component, you can describe its props inline. A named type or interface is easier to read and reuse as the shape grows.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →interface GreetingProps {
name: string;
}
function Greeting({ name }: GreetingProps) {
return <h1>Hello, {name}!</h1>;
}
Here, name is required and must be a string wherever Greeting is used. The type also helps editors show the component’s expected inputs. You generally do not need to add a return-type annotation just for formality when TypeScript can infer the result.
Let Hooks infer types when they can
React’s type definitions cover built-in Hooks. When the initial value makes the state’s type clear, useState can infer it:
import { useState } from 'react';
function Toggle() {
const [enabled, setEnabled] = useState(false);
return (
<button onClick={() => setEnabled(!enabled)}>
{enabled ? 'On' : 'Off'}
</button>
);
}
Because the initial value is false, TypeScript infers a boolean state. When the initializer alone cannot express the intended type, provide a type argument. For example, an initially empty array that will contain strings can be written as useState<string[]>([]).
Use the editor to identify event types
React event handlers are typed, but the best event type depends on the element and handler. Rather than guessing, write the handler in the JSX attribute and hover over its parameter in your editor to inspect the inferred type. If no more specific event type is included, React’s guide identifies React.SyntheticEvent as the base type.
function NameField() {
function handleChange(event: React.ChangeEvent<HTMLInputElement>) {
console.log(event.currentTarget.value);
}
return <input onChange={handleChange} />;
}
The example uses an input change event. In other handlers, inspect the type for the particular JSX attribute rather than copying this event type indiscriminately.
Best Value
Choose a children type that matches the component
Use React.ReactNode when a component accepts broadly renderable content, such as text or JSX. Use React.ReactElement when the prop specifically needs to be a JSX element.
| Type | Use it when | What it does not guarantee |
|---|---|---|
React.ReactNode |
The component can accept a broad range of renderable children. | It does not limit children to a particular JSX tag. |
React.ReactElement |
The component requires a JSX element as its child prop. | It does not limit that element to a specific tag such as <li>. |
interface PanelProps {
children: React.ReactNode;
}
function Panel({ children }: PanelProps) {
return <section>{children}</section>;
}
Type inline styles when you need them
React documents React.CSSProperties for a style object. It gives the object a suitable type while you define or reuse it:
const panelStyle: React.CSSProperties = {
padding: '1rem',
backgroundColor: 'white',
};
Know what TypeScript does—and does not—check
TypeScript describes the shapes and values expected by your code and checks them during development. A type annotation does not inspect an API response or otherwise validate data at runtime. If your application relies on external data being a particular shape, validate it at runtime before treating it as that type.
Quick Recap
Where to continue learning
- Use the TypeScript Handbook to learn core language features such as types, interfaces, and generics.
- Consult the community-maintained React TypeScript Cheatsheet for React-specific patterns beyond these first components.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




