Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

A generic type alias is a parameterized named reference to an existing type, declared using the typedef keyword. It allows developers to bind type parameters to complex or verbose type signatures, creating a shorthand identifier that remains structurally equivalent to the underlying type.
typedef AliasName<T> = TargetType<T>;

Technical Characteristics

Type Equivalence Dart resolves type aliases structurally, not nominally. A generic type alias does not instantiate a new, distinct type in the Dart type system. The alias and its underlying type are completely interchangeable and evaluate to the exact same runtime type. Type Parameter Forwarding Type variables declared on the left side of the assignment (=) act as placeholders that are forwarded to the target type on the right side. You can forward all, some, or none of the type parameters to the underlying type. Partial Type Application Generic aliases can be used to partially apply type arguments to an existing generic type, hardcoding specific types for certain parameters while leaving others generic.

Syntax Variations

Function Types Aliases are frequently applied to generic function signatures to define strict contract requirements for callbacks or higher-order functions.
typedef Transformer<T, R> = R Function(T element);
Collections Aliases can wrap nested or complex generic collection types.
typedef Matrix<T> = List<List<T>>;
Records With the introduction of Records in Dart 3, generic aliases can define parameterized positional or named record structures.
typedef Result<T, E> = (T? data, E? error);
Partial Application Binding one type parameter while exposing another.
// Binds the key type to String, leaving the value type generic
typedef StringMap<V> = Map<String, V>; 

Type Bounds

Generic type aliases support type parameter constraints using the extends keyword. This enforces that any type passed to the alias conforms to a specific class hierarchy or interface.
typedef NumericMatrix<T extends num> = List<List<T>>;
If a bound is applied to the alias, any instantiation of that alias must satisfy the bound during static analysis. If the underlying type also has bounds, the alias’s bounds must be equal to or stricter than the underlying type’s bounds.
Master Dart with Deep Grasping Methodology!Learn More