avoid_double_and_int_checks
Avoid double
and int
checks.
此规则自 Dart 2.0 版本起可用。
详情
#AVOID to check if type is double
or int
.
When compiled to JS, integer values are represented as floats. That can lead to some unexpected behavior when using either is
or is!
where the type is either int
or double
.
BAD:
dart
f(num x) {
if (x is double) {
...
} else if (x is int) {
...
}
}
GOOD:
dart
f(dynamic x) {
if (x is num) {
...
} else {
...
}
}
使用方法
#要启用 avoid_double_and_int_checks
规则,请在你的 analysis_options.yaml
文件中,在 linter > rules 下添加 avoid_double_and_int_checks
:
analysis_options.yaml
yaml
linter:
rules:
- avoid_double_and_int_checks
除非另有说明,否则本网站上的文档反映的是 Dart 3.6.0。页面最后更新于 2025-02-05。 查看源代码 或 报告问题.