avoid_type_to_string
避免
詳情
#請 避免在生產程式碼中呼叫
不推薦
dart
void bar(Object other) {
if (other.runtimeType.toString() == 'Bar') {
doThing();
}
}
Object baz(Thing myThing) {
return getThingFromDatabase(key: myThing.runtimeType.toString());
}推薦
dart
void bar(Object other) {
if (other is Bar) {
doThing();
}
}
class Thing {
String get thingTypeKey => ...
}
Object baz(Thing myThing) {
return getThingFromDatabase(key: myThing.thingTypeKey);
}啟用
#要在您的 analysis_options.yaml 檔案中啟用 avoid_type_to_string 規則,請在 linter > rules 下新增 avoid_type_to_string
analysis_options.yaml
yaml
linter:
rules:
- avoid_type_to_string如果您使用 YAML 對映語法來配置 Linter 規則,請在 linter > rules 下新增 avoid_type_to_string: true
analysis_options.yaml
yaml
linter:
rules:
avoid_type_to_string: true