prefer_generic_function_type_aliases
Prefer generic function type aliases.
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:
typedef void F();
GOOD:
typedef F = void Function();
Enable
#To enable the prefer_generic_function_type_aliases
rule,
add prefer_generic_function_type_aliases
under linter > rules in your
analysis_options.yaml
file:
linter:
rules:
- prefer_generic_function_type_aliases
If you're instead using the YAML map syntax to configure linter rules,
add prefer_generic_function_type_aliases: true
under linter > rules:
linter:
rules:
prefer_generic_function_type_aliases: true
除非另有说明,文档之所提及适用于 Dart 3.7.0 版本,本页面最后更新时间: 2025-01-27。 查看文档源码 或者 报告页面问题。