prefer_generic_function_type_aliases
倾向于使用泛型函数类型别名。
详情
#倾向于使用泛型函数类型别名。
随着泛型函数的引入,函数类型别名 (typedef void F()) 无法表达用户可能想要表达的所有可能的参数化类型。泛型函数类型别名 (typedef F = void Function()) 解决了这个问题。
为了保持一致性和可读性,最好只使用一种语法,因此倾向于使用泛型函数类型别名。
差
dart
typedef void F();好
dart
typedef F = void Function();启用
#要启用 prefer_generic_function_type_aliases 规则,请在您的 analysis_options.yaml 文件中的 linter > rules 下添加 prefer_generic_function_type_aliases
analysis_options.yaml
yaml
linter:
rules:
- prefer_generic_function_type_aliases如果您使用 YAML 映射语法配置 linter 规则,请在 linter > rules 下添加 prefer_generic_function_type_aliases: true
analysis_options.yaml
yaml
linter:
rules:
prefer_generic_function_type_aliases: true