checkValid<T> method

T checkValid<T>(
  1. String key
)

Implementation

T checkValid<T>(String key) {
  final element = this[key];
  if (element == null) {
    throw FormatException("Missing key '$key'");
  }
  if (element is! T) {
    throw FormatException(
      'Expected element of type $T but got element of type '
      '${element.runtimeType}.',
    );
  }
  return element as T;
}