# getKeyType method

ResolvableType getKeyType()

Returns the key type for Map-like types.

For Map types, this method returns a ResolvableType representing the key type (the first generic parameter). For non-Map types, this returns ResolvableType.NONE.

Returns:

- ResolvableType representing the key type for Maps
- ResolvableType.NONE if this is not a Map type

Example:

    final stringIntMapType = ResolvableType.forClass(Map<String, int>);
    final intStringMapType = ResolvableType.forClass(Map<int, String>);
    final listType = ResolvableType.forClass(List<String>);

    final stringKeyType = stringIntMapType.getKeyType();
    print(stringKeyType.resolve()?.getType()); // String

    final intKeyType = intStringMapType.getKeyType();
    print(intKeyType.resolve()?.getType()); // int

    final noKeyType = listType.getKeyType();
    print(noKeyType == ResolvableType.NONE); // true

    // Useful for Map processing
    void processMapType(ResolvableType type) {
      final keyType = type.getKeyType();
      if (keyType != ResolvableType.NONE) {
        final valueType = type.getGeneric([1]); // Second generic parameter
        print("Map with keys: ${keyType.resolve()?.getType()}");
        print("Map with values: ${valueType.resolve()?.getType()}");
      }
    }

## Implementation

    ResolvableType getKeyType() {
      if (this == NONE) return NONE;

      final resolved = resolve();
      if (resolved != null) {
        final clazz = Class.forType(resolved.getType());
        if (clazz.isAssignableTo(Class.forType(Map))) {
          final generics = getGenerics();
          if (generics.isNotEmpty) {
            return generics[0];
          }
        }

        final keyClass = resolved.keyType();
        if (keyClass != null) {
          return forType(keyClass.getType(), this);
        }
      }

      return NONE;
    }