isAssignableFrom abstract method
Type Assignability Table:
DART TYPE ASSIGNABILITY TABLE
────────────────────────────────────────────────────────────────────────────
From (B) → To (A) A.isAssignableFrom(B) Valid? Notes
────────────────────────────────────────────────────────────────────────────
Object ← String ✅ true ✅ String extends Object
String ← Object ❌ false ❌ Super not assignable from subclass
num ← int ✅ true ✅ int is a subclass of num
int ← num ❌ false ❌ num is broader than int
List<int> ← List<int> ✅ true ✅ Same type
List<T> ← List<S> ❌ false ❌ Dart generics are invariant
List<dynamic> ← List<int> ❌ false ❌ Still invariant
A ← B (B extends A) ✅ true ✅ Subclass to superclass is OK
A ← C (unrelated) ❌ false ❌ No inheritance/interface link
Interface ← Class implements Itf ✅ true ✅ Implements is assignable to interface
Mixin ← Class with Mixin ✅ true ✅ Mixed-in type present
dynamic ← anything ✅ true ✅ dynamic accepts all types
anything ← dynamic ✅ true (unsafe) ✅ Allowed but unchecked
Never ← anything ❌ false ❌ Never can’t accept anything
anything ← Never ✅ true ✅ Never fits anywhere (bottom type)
────────────────────────────────────────────────────────────────────────────
RULE OF THUMB:
A.isAssignableFrom(B) → Can you do: A a = B();
✓ Subclass → Superclass: OK
✗ Superclass → Subclass: Not OK
✓ Class implements Interface → Interface: OK
✗ Interface → Class: Not OK
✓ Identical types: OK
✗ Unrelated types: Not OK
Checks if this type is assignable from the given other
type.
Returns true
if a value of type other
can be assigned to a variable of this type.
This follows Dart's assignability rules including inheritance, interfaces, and mixins.
Implementation
bool isAssignableFrom(TypeDeclaration other);