目录

prefer_generic_function_type_aliases

目录

Prefer generic function type aliases.

This rule is available as of Dart 2.0.

Rule sets: core, recommended, flutter

This rule has a quick fix available.

Details

#

PREFER generic function type aliases.

With the introduction of generic functions, function type aliases (typedef void F()) couldn't express all of the possible kinds of parameterization that users might want to express. Generic function type aliases (typedef F = void Function()) fixed that issue.

For consistency and readability reasons, it's better to only use one syntax and thus prefer generic function type aliases.

BAD:

dart
typedef void F();

GOOD:

dart
typedef F = void Function();

Usage

#

To enable the prefer_generic_function_type_aliases rule, add prefer_generic_function_type_aliases under linter > rules in your analysis_options.yaml file:

analysis_options.yaml
yaml
linter:
  rules:
    - prefer_generic_function_type_aliases