invalid-runtime-check-with-js-interop-types
Same as invalid_runtime_check_with_js_interop_types in Dart lints
- Group
- Correctness
- Path
lint/correctness/invalid-runtime-check-with-js-interop-types- Default
- On (recommended)
- Origin
- Dart lints
- Rule
- 248 of 512
Reject platform-dependent runtime checks involving JavaScript interop types.
Invalid
import 'dart:js_interop';
import 'dart:core';
import 'dart:core' as core;
extension type MyJs(JSObject value) {}
extension type OtherJs(JSObject value) {}
@JS()
@staticInterop
class StaticJs {}
bool dartAgainstJs(Object value) => value is JSObject;
bool jsAgainstDart(JSAny value) => value is String;
bool unrelatedUsers(MyJs value) => value is OtherJs;
String invalidCast(JSAny value) => value as String;
bool anyIsObject(JSAny value) => value is JSObject;
bool nestedGeneric(List<JSAny> value) => value is List<JSObject>;
bool nestedRecord((JSAny,) value) => value is (JSObject,);
void catchesInterop() {
try {
throw StateError('x');
} on JSAny catch (error) {
error;
}
}
bool dynamicIsInterop(dynamic value) => value is JSAny;
// Explicit core prefixes exercise SDK-free imported identity resolution too.
void catchesNestedInterop<T extends JSNumber>() {
try {
throw StateError('nested');
} on core.List<JSString> catch (error) {
error;
} on core.List<T> catch (error) {
error;
}
} bool dartAgainstJs(Object value) => value is JSObject;bool dartAgainstJs(Object value) => value is JSObject;bool jsAgainstDart(JSAny value) => value is String;bool jsAgainstDart(JSAny value) => value is String;bool unrelatedUsers(MyJs value) => value is OtherJs;bool unrelatedUsers(MyJs value) => value is OtherJs;String invalidCast(JSAny value) => value as String;String invalidCast(JSAny value) => value as String;bool anyIsObject(JSAny value) => value is JSObject;bool anyIsObject(JSAny value) => value is JSObject;bool nestedGeneric(List<JSAny> value) => value is List<JSObject>;bool nestedGeneric(List<JSAny> value) => value is List<JSObject>;bool nestedRecord((JSAny,) value) => value is (JSObject,); throw StateError('x'); } on JSAny catch (error) { bool dynamicIsInterop(dynamic value) => value is JSAny; throw StateError('nested'); } on core.List<JSString> catch (error) { error; } on core.List<T> catch (error) {Valid
import 'dart:js_interop';
extension type MyJs(JSObject value) {}
bool sameSdk(JSAny value) => value is JSAny;
bool sdkSubtype(JSArray<JSAny> value) => value is JSObject;
bool typedArraySubtype(JSUint8Array value) => value is JSObject;
bool sameUser(MyJs value) => value is MyJs;
bool nestedSubtype(List<JSArray<JSAny>> value) => value is List<JSObject>;
bool functionParameterSubtype(void Function(JSAny) value) =>
value is void Function(JSObject);
bool functionReturnSubtype(JSObject Function() value) =>
value is JSAny Function();
bool ordinary(Object value) => value is String;
JSAny objectAsAny(Object value) => value as JSAny;
JSObject anyAsObject(JSAny value) => value as JSObject;
Object dynamicSource(dynamic value) => value as JSAny;
// The analyzer's `canBeSubtypeOf` never descends into function types.
bool functionParameterWrongDirection(void Function(JSObject) value) =>
value is void Function(JSAny);
bool functionReturnWrongDirection(JSAny Function() value) =>
value is JSObject Function();
// Null normalizes to Never, so it does not trigger an interop runtime lint.
bool nullIsInterop() => null is JSAny;
JSAny nullAsInterop() => null as JSAny;
void catchesOrdinary() {
try {
throw StateError('ordinary');
} on List<String> catch (error) {
error;
}
}Configure invalid-runtime-check-with-js-interop-types
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"correctness": {
"invalid-runtime-check-with-js-interop-types": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/correctness/invalid-runtime-check-with-js-interop-types: <reason>More correctness rules
- library-private-types-in-public-api
library_private_types_in_public_apirecommendedAvoid using library-private types in public APIs.
- list-all-equatable-fieldsrecommendedequatable
Flags declared instance fields omitted from a statically understood Equatable props list.
- literal-only-boolean-expressions
literal_only_boolean_expressionsrecommendedFlags conditions built only from literals, whose value never changes.
- match-getter-setter-field-names
Detect likely copy-paste errors in trivial accessors when a different field matching the accessor name is declared.
- missing-test-assertionrecommendedtest
Reports inline test callbacks that contain no recognized assertion calls.
- no-adjacent-strings-in-list
no_adjacent_strings_in_listrecommendedFlags adjacent string literals used as an element of a list or set literal.
- no-import-cyclescross-file
Report mutually dependent components of imported or exported library files.
- no-logic-in-create-state
no_logic_in_create_staterecommendedflutterRequire
StatefulWidget.createStateto return only a fresh zero-argument FlutterStateconstruction.