Type component props and children
Add types without changing the interface
TypeScript checks the shapes of values before a program runs. React still renders JavaScript at runtime. A TSX file contains TypeScript plus JSX; the build tool removes type annotations and transforms JSX. The compiler can catch a missing required prop, but it does not ensure the text is meaningful or the component is accessible. This chapter assumes the earlier components, props and state lessons plus basic TypeScript types. Each app snippet is independent. Use a reviewed React 19 and matching React DOM and type packages, a compatible TypeScript compiler and a TSX build tool. Exact dependency patches are not yet approved.
import React from 'react';function Exhibit({title, room = 'Main hall'}) { return <article><h2>{title}</h2><p>{room}</p></article>;}export default function App() { return <Exhibit title="Ceramic bowl"/>; }The card displays Ceramic bowl and Main hall. A caller could accidentally pass a number for the title; JavaScript alone does not enforce this component contract.
Describe the props with a type
import React from 'react';type ExhibitProps = { readonly title: string; readonly room?: string };function Exhibit({title, room = 'Main hall'}: ExhibitProps) { return <article><h2>{title}</h2><p>{room}</p></article>;}export default function App() { return <Exhibit title="Ceramic bowl"/>; }The visible result is identical. The question mark permits omitting room; the default is used for undefined, not null. With strict null checks, null is rejected for this prop. A title number is a type error. The readonly fields discourage assignment through this typed object; they do not freeze it at runtime or recursively protect nested objects. An interface could express the same shape. Let TypeScript infer the component return type unless an explicit boundary helps. React.FC is optional.
Choose a type for composition
import React from 'react';import type {ReactNode, ReactElement} from 'react';type PanelProps = { title: string; children: ReactNode; badge: ReactElement; tone?: 'neutral' | 'highlight' };function Panel({title,children,badge,tone='neutral'}: PanelProps): React.JSX.Element { return <section data-tone={tone}><h2>{title}</h2>{badge}<div>{children}</div></section>;}export default function App(){return <Panel title="Gallery" badge={<strong>Open</strong>} tone="highlight">Free entry</Panel>;}The panel displays Gallery, Open and Free entry. ReactNode permits ordinary renderable content such as text, numbers, elements and null; the exact union depends on installed React types. ReactElement describes a React element object rather than arbitrary renderable content. Neither ensures a particular HTML tag or meaningful content. The explicit return annotation uses the scoped React.JSX namespace in React 19 types; older code may use global JSX.Element. Prefer inference for portable simple components. The tone union limits caller choices but does not validate JSON at runtime.
Check before shipping
In an approved TSX project, use a tsconfig with strict: true, jsx: react-jsx, suitable DOM and ECMAScript libraries, module resolution compatible with the bundler, and noEmit: true for the checking step. Run tsc --noEmit -p tsconfig.json using the pinned local compiler. A successful transpilation or Vite build alone does not establish semantic type correctness. Change the typed title to a number, omit title, pass a string badge and try an unsupported tone; the checker should reject each. Restore the valid source before running the browser. Actual React type checks are pending in this package.