isAssignableTo abstract method

bool isAssignableTo(
  1. TypeDeclaration target
)

Type Assignability Table:

DART TYPE ASSIGNABILITY TABLE
────────────────────────────────────────────────────────────────────────────
From (A) → To (B)                   A.isAssignableTo(B)   Valid?   Notes
────────────────────────────────────────────────────────────────────────────
String    → Object                 ✅ true               ✅      String extends Object
Object    → String                 ❌ false              ❌      Superclass to subclass not allowed
int       → num                    ✅ true               ✅      int is a subtype of num
num       → int                    ❌ false              ❌      Can't assign broader to narrower
List<int> → List<int>              ✅ true               ✅      Identical type
List<S>   → List<T>                ❌ false              ❌      Dart generics are invariant
List<int> → List<dynamic>          ❌ false              ❌      Invariant generics
B         → A (B extends A)        ✅ true               ✅      Subclass to superclass: OK
C         → A (no relation)        ❌ false              ❌      Unrelated types
Class     → Interface (implements) ✅ true               ✅      Implements interface
Class     → Mixin (with mixin)     ✅ true               ✅      Class includes mixin
anything  → dynamic                ✅ true               ✅      Everything is assignable to dynamic
dynamic   → anything               ✅ true (unchecked)   ✅      Allowed but unsafe
anything  → Never                  ❌ false              ❌      Can't assign anything to Never
Never     → anything               ✅ true               ✅      Never fits anywhere
────────────────────────────────────────────────────────────────────────────

RULE OF THUMB:
A.isAssignableTo(B) → Can you do: B b = A();
✓ Subclass → Superclass: OK
✗ Superclass → Subclass: Not OK
✓ Class → Interface it implements: OK
✗ Interface → Class: Not OK
✓ Identical types: OK
✗ Unrelated types: Not OK

Checks if this type is assignable to the given target type.

Returns true if a value of this type can be assigned to a variable of type target. This is the inverse of isAssignableFrom.

Implementation

bool isAssignableTo(TypeDeclaration target);