TypeDeclaration class abstract

Represents metadata information about any Dart type — including classes, enums, typedefs, generic types like List<int>, and even nullable types.

You can use this class to:

  • Introspect type names and type arguments
  • Determine type kind (list, map, class, enum, etc.)
  • Resolve the declaration (e.g., to ClassDeclaration or EnumDeclaration)
  • Perform runtime type comparisons or assignability checks

Example

final type = reflector.reflectType(MyClass);
print(type.getName()); // MyClass

if (type.asClassType() != null) {
  final reflectedClass = type.asClassType()!;
  print(reflectedClass.getConstructors());
}
Inheritance
Implementers
Available extensions

Constructors

TypeDeclaration()
Represents metadata information about any Dart type — including classes, enums, typedefs, generic types like List<int>, and even nullable types.
const

Properties

hashCode int
The hash code for this object.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

asClass() ClassDeclaration?

Available on TypeDeclaration, provided by the TypeDeclarationExtension extension

Safely casts to ClassDeclaration if possible.
asEnum() EnumDeclaration?

Available on TypeDeclaration, provided by the TypeDeclarationExtension extension

Safely casts to EnumDeclaration if possible.
asMixin() MixinDeclaration?

Available on TypeDeclaration, provided by the TypeDeclarationExtension extension

Safely casts to MixinDeclaration if possible.
asRecord() RecordDeclaration?

Available on TypeDeclaration, provided by the TypeDeclarationExtension extension

Safely casts to RecordDeclaration if possible.
asTypedef() TypedefDeclaration?

Available on TypeDeclaration, provided by the TypeDeclarationExtension extension

Safely casts to TypedefDeclaration if possible.
asTypeVariable() TypeVariableDeclaration?

Available on TypeDeclaration, provided by the TypeDeclarationExtension extension

Safely casts to TypeVariableDeclaration if possible.
getDartType() → DartType?
The analyzer DartType of the entity for enhanced type operations.
inherited
getDebugIdentifier() String
The debug identifier for the entity.
override
getDeclaration() SourceDeclaration?

Available on TypeDeclaration, provided by the TypeDeclarationExtension extension

Resolves the most specific declaration type.
getElement() → Element?
The analyzer element associated with this declaration.
inherited
getInterfaces() List<LinkDeclaration>
Returns the list of interfaces this type implements.
getIsNullable() bool
Returns true if the type is nullable, such as 'String?' or 'int?'.
getIsPublic() bool
Checks if this declaration is a public declaration.
inherited
getIsSynthetic() bool
Checks if a declaration is a synthetic declaration.
inherited
getKind() TypeKind
Returns the TypeKind of this type, indicating whether it is a class, enum, mixin, etc.
getMixins() List<LinkDeclaration>
Returns the list of mixin identities that are applied to this type.
getName() String
Gets the name of the declared element.
inherited
getPackageUri() String
Returns the package URI where this type is declared.
getQualifiedName() String
Returns the fully qualified name of this type.
getSimpleName() String
Returns the simple name of the type without the package or library URI.
getSuperClass() LinkDeclaration?
Returns the direct superclass of this type.
getType() Type
Gets the runtime type of the declared element.
inherited
getTypeArguments() List<LinkDeclaration>
Returns the list of type arguments for generic types.
hasAnalyzerSupport() bool
Returns true if this declaration has analyzer information available.
inherited
isAssignableFrom(TypeDeclaration other) bool
Type Assignability Table:
isAssignableTo(TypeDeclaration target) bool
Type Assignability Table:
isGeneric() bool
Check if this is a generic type.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() Map<String, Object>
Returns a JSON representation of this entity.
override
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
override