In Dart, you can use a typedef
to define type aliases for your function and non-function types.
They make your code more concise, so you can avoid repeating long type names. 👌
Typedefs are particularly useful for functions with many arguments or complex types with generics. 👍
Example:
typedef SpecialMap = Map<int, String>;
void main() {
final specialMap = SpecialMap();
specialMap[1] = 'one'; // ok
specialMap.addAll({'2': 'two'}); // The element type 'String' can't be assigned to the map key type 'int'
}