typedef keyword, it establishes a semantic reference to a data type, function signature, or generic structure without creating a new unique class or interface.
Syntax
The syntax allows aliasing any type, including functions, collections, and records.Type Equality and Identity
A type alias does not introduce a new type into the Dart type system; it is strictly a compile-time abstraction. The alias and the underlying type are fully interchangeable and semantically identical.- Static Analysis: Variables declared with the alias are treated exactly as the underlying type.
- Instance Checks: The
isoperator evaluates totruefor both the alias and the underlying type. - Type Object Equality: The
Typeobject of the alias is identical to theTypeobject of the underlying type.
Function Type Aliases
Aliases are frequently used to define signatures for callbacks or higher-order functions. This allows the definition of a specific function signature to be reused across multiple parameters or variables.Generic Type Aliases
Type aliases support generics, allowing the alias to pass type parameters to the underlying type. This enables the creation of specialized names for complex generic structures.Record Type Aliases
Aliases can assign identifiers to Record types. Since records are structurally typed and anonymous by default, aliases provide a nominal handle for referring to specific record shapes.Recursive Type Aliases
Recursion in type aliases is restricted based on the nature of the type being aliased.- Function Types: Recursive references are permitted. A typedef for a function can reference itself in its signature (e.g., for state machines or callbacks).
- Non-Function Types: Recursive references are not permitted. A typedef for a class, list, or map cannot refer to itself directly or indirectly, as this would result in an infinite expansion of the type.
Master Dart with Deep Grasping Methodology!Learn More





