AcceptedTypes class

Used to annotate fields or parameters that have a type Object, but should only receive a known subset of types (e.g. String and int).

The intention of this annotation is to help avoid passing an incorrect or unexpected value.

For example:

void fn() {
 fn(1); // LINT
 SomeClass(false); // LINT
}

void fn(@AcceptedTypes({String, bool}) Object value) {}

class SomeClass {
 @AcceptedTypes({String, int})
 final Object field;

 const SomeClass(this.field);
}

DCM will provide feedback if an invocation receives an argument that does not match the type listed in the @AcceptedTypes().

For more information, see the documentation for "pass-correct-accepted-types".

Constructors

AcceptedTypes.new(Set<Type>? types)
Create a new instance of AcceptedTypes to be used as an annotation on a declaration that have an Object type, but should only receive a known subset of types.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
types Set<Type>?
The types which the annotated declaration accepts.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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