Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

To give a generic type parameter a default in TypeScript, add = Type to the parameter—for example, type Box<T = unknown> = { value: T };. The default makes that type argument optional; it does not create a runtime value or make a required prop optional. For component APIs, it can keep common call sites concise while still allowing inference or an explicit type argument to supply a more specific type.

How do you give a generic type parameter a default in TypeScript?

Write the default after the type parameter name:

type Box<T = unknown> = { value: T };

const box: Box = { value: "ready" };
const numericBox: Box<number> = { value: 42 };

In Box, omitting the type argument uses unknown; specifying number overrides the default. As the TypeScript Handbook explains, “By declaring a default for a generic type parameter, you make it optional to specify the corresponding type argument.”

The rules that matter when designing a reusable type are:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • A parameter with a default is optional. Required type parameters must come before optional ones.
  • The default must satisfy any constraint on that parameter.
  • If an argument is omitted, TypeScript uses the default when inference cannot choose a candidate. When inference can determine a type, it can preserve that more specific type instead.

For example, this is valid because the required TValue comes before the defaulted TOption:

type SelectProps<
  TValue,
  TOption = { value: TValue; label: string }
> = {
  value: TValue;
  options: TOption[];
};

A declaration with a required parameter after a defaulted one is not valid:

// Invalid: a required parameter cannot follow an optional one.
type Invalid<TOption = unknown, TValue> = { value: TValue };

If you add a constraint to TOption, its default must meet that constraint too. These ordering and constraint rules are documented in the TypeScript 2.3 release notes.

Rank #2
TypeScript Programming Language - Software Engineer & Coder T-Shirt
  • 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

How can a generic React component’s props stay easy to use and type-safe?

Give the component and its props type the same generic parameter so that the data and the rendering callback remain connected:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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 the supplied data, that type can flow into render. If no type argument is inferred, the default is unknown; a caller can also specify a type argument explicitly where appropriate. The generic default is a fallback for the type argument, not a substitute for inference.

Choosing unknown is useful when a fallback should require callers to narrow or otherwise establish a value’s type before using it. By contrast, any can suppress useful checks. That choice is API-design guidance: pick a default that communicates what callers may safely assume.

What a generic default does—and what it does not do

A generic default affects static type arguments. It does not supply a prop at runtime, and it does not turn a required prop into an optional one. In the Panel example, data remains required because the props type declares it as a required property.

Mechanism What it changes Where it applies
Generic parameter default, such as TData = unknown Makes the corresponding type argument optional; the default is used when no inferred candidate is available. Static type checking.
Runtime parameter or property default Provides a value when an argument or property is omitted, according to the relevant runtime syntax. Runtime behavior. TypeScript’s 1.8 release notes and 3.0 release notes show function-component parameter defaults as a separate technique.
React defaultProps and JSX prop checking Involves library-aware transformation of props for JSX checking; it is not a generic type-argument default. JSX typing. TypeScript 3.0 documents JSX.LibraryManagedAttributes and caveats involving explicit annotations and React type definitions in its release notes.

These mechanisms can appear in the same component API, but they answer different questions: what type should an omitted type argument use, what runtime value should an omitted prop receive, and how should JSX check props in light of library-specific behavior?

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When is a default better than an overload or a required type argument?

Use a generic default when there is a sensible common fallback and callers should still be able to override it. The TypeScript 2.3 release notes illustrate how defaults can replace a family of overloads for a container factory with a single signature.

  • Prefer a default when omitting the type argument should select a meaningful fallback and explicit overrides remain useful.
  • Rely on inference when arguments already provide enough information for TypeScript to infer the intended type; a default need not replace a useful inferred type.
  • Require an explicit argument when there is no safe or meaningful fallback and callers should make the choice themselves.
  • Keep overloads when different call forms need distinct signatures or behavior, rather than merely different fallback type arguments.

For JSX, TypeScript 2.9 added support for supplying generic type arguments directly in JSX, as in <GenericComponent<Props> ... />; see the TypeScript 2.9 release notes. This is separate from the rule that a generic parameter may have a default. TypeScript 5.1’s JSX.ElementType concerns which types a JSX library permits as tags, not generic parameter defaults; the distinction is covered in the TypeScript 5.1 release notes.

Is this really an underused TypeScript feature in 2026?

Generic parameter defaults are established TypeScript functionality, introduced in TypeScript 2.3, whose release notes were published in 2017. The official documentation does not establish how widely developers use the feature, so “underused” is not a measured adoption claim. Its value is practical rather than novel: a default can reduce repetitive type arguments in a reusable API without removing callers’ ability to provide a more specific type.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.