Typedefs

A type alias—often called a typedef because it's declared with the keyword typedef—is a concise way to refer to a type. Here's an example of declaring and using a type alias named IntList:

dart
typedef IntList = List<int>;
IntList il = [1, 2, 3];

A type alias can have type parameters:

dart
typedef ListMapper<X> = Map<X, List<X>>;
Map<String, List<String>> m1 = {}; // Verbose.
ListMapper<String> m2 = {}; // Same thing but shorter and clearer.

We recommend using inline function types instead of typedefs for functions, in most situations. However, function typedefs can still be useful:

dart
typedef Compare<T> = int Function(T a, T b);

int sort(int a, int b) => a - b;

void main() {
  assert(sort is Compare<int>); // True!
}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy