Skip to main content

ExtractMapType

A type that extracts the generic type parameters from a Map type. It extracts K and V from a type like Map<K, V> and returns them as a tuple [K, V].


Interface

typescript
type ExtractMapType<T> = T extends Map<infer K, infer V>
? [K, V]
: never;

Usage

Basic Case

typescript
import { ExtractMapType } from '@modern-kit/types';

type StringNumberMap = Map<string, number>;
type Extracted = ExtractMapType<StringNumberMap>; // [string, number]

Non-Map Type

typescript
import { ExtractMapType } from '@modern-kit/types';

type NotMap = ExtractMapType<number>; // never