Free tools Windows power users keep installed
One-click scans. No signup required.
To give a generic type parameter a default in TypeScript, write = Type after the parameter, as in type Props<T = unknown> = .... The default makes that type argument optional: callers can omit it when the fallback is suitable, while inference or an explicit argument can provide a more specific type. For component props, this can make reusable signatures easier to call without making runtime props optional.
How do I give a generic type parameter a default in TypeScript?
Put the default directly in the generic parameter list:
As an Amazon Associate I earn from qualifying purchases.
type Box<T = unknown> = { value: T };
Now Box is valid without a type argument and is treated as Box<unknown>. A caller can still write Box<string> to choose a specific type. The TypeScript Handbook summarizes the rule: “By declaring a default for a generic type parameter, you make it optional to specify the corresponding type argument.” See the TypeScript Handbook’s Generics section.
Rules that determine when the default applies
- A type parameter with a default is optional; required type parameters must come before parameters with defaults.
- The default must satisfy the type parameter’s constraint.
- If a type argument is omitted, TypeScript uses inference where it can select a candidate; if inference cannot choose one, it uses the default.
These rules are documented in the Handbook and the TypeScript 2.3 release notes. For example, type Pair<T, U = T[]> = ... is ordered correctly: T is required and U is optional. Reversing them to put a required parameter after a defaulted one is not allowed.
#1 Best Overall
How can a default make a generic component’s props easier to use?
A component can use one type parameter in more than one prop, so the value and the function that consumes it stay connected:
import type { ReactNode } from "react";
type PanelProps<TData = unknown> = {
data: TData;
render: (data: TData) => ReactNode;
};
function Panel<TData = unknown>({ data, render }: PanelProps<TData>) {
return <section>{render(data)}</section>;
}
When TypeScript can infer TData from a call, it can use that specific type for both data and the render callback. If there is no inferred candidate and the caller omits the type argument, the declared fallback is unknown. A caller can also provide an explicit argument when needed. This example applies the Handbook’s generic-default and inference rules to a React-style component; it does not depend on a particular React or TypeScript release.
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
A default for an optional trailing type parameter
A default is especially useful when one part of a reusable props type should remain required while another part has a sensible conventional shape:
type SelectProps<
TValue,
TOption = { value: TValue; label: string }
> = {
value: TValue;
options: TOption[];
};
Here, callers must supply or infer TValue, while TOption can be omitted and falls back to an object whose value uses that same type. If you add a constraint to TOption, its default must meet that constraint too. A required type parameter cannot follow TOption because it has a default.
Choose a fallback that preserves the intended safety
unknown is a cautious fallback: code must narrow or otherwise establish the value’s type before using it as a more specific type. any is more permissive and can suppress useful checks. Pick the default that expresses what callers should be able to assume when they omit the argument; a default is part of the API’s type contract, not merely a way to shorten syntax.
What a generic default does—and does not do
A generic default affects type arguments at compile time. It does not supply a value for a missing prop, make a required prop optional, or alter component behavior at runtime. In the Panel example, data and render remain required properties regardless of the default for TData.
Runtime parameter defaults are separate
A function parameter default provides an actual runtime value when an argument is omitted. TypeScript’s 1.8 release notes discuss parameter defaults in function components as a way to handle props such as name. That solves a different problem from choosing a type argument.
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 →React defaultProps and JSX checking are separate too
React’s defaultProps and the way JSX checks component props involve library-aware typing. TypeScript 3.0 introduced JSX.LibraryManagedAttributes to transform props for JSX checking, including behavior related to defaultProps, with caveats involving explicit annotations and React type definitions. Those rules are not generic parameter defaults; the details are in the TypeScript 3.0 release notes.
Best Value
When should you use a generic default instead of overloads or explicit arguments?
Use a default when there is a meaningful fallback and callers should be allowed to omit the corresponding type argument. The TypeScript 2.3 release notes show how defaults can replace a family of overloads for a container factory with one signature. The choice depends on the API:
- Prefer a default when a common fallback keeps the signature clear and callers can still override it.
- Prefer inference when the arguments already provide enough information for TypeScript to select the desired type; a default is not a reason to give up useful inference.
- Require an explicit type argument when silently choosing a fallback would hide an important distinction or encourage unsafe assumptions.
- Use overloads when different call shapes or return types need to be represented, rather than merely to make one type argument optional.
In each case, check that the default satisfies constraints and remember that a generic default changes static typing only. It does not implement a runtime fallback for props.
How generic component typing has evolved
Generic parameter defaults have been part of TypeScript since version 2.3; they are not a feature introduced in 2026. TypeScript 2.9 later added the ability to supply generic type arguments in JSX, such as <GenericComponent<Props> ... />, as described in the TypeScript 2.9 release notes. TypeScript 5.1 added JSX.ElementType, allowing a JSX library to specify which types may be used as tags; that is adjacent JSX typing history, not a change to generic defaults, as noted in the TypeScript 5.1 release notes.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesThe official documentation establishes the language rules and historical release points, but it does not provide adoption data showing that generic defaults are underused. The useful case for them is practical: they can make the common call concise while preserving an explicit route to a different type when the API needs one.
Quick Recap
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.




