To implement a mapped type, utilize the syntax {[K in keyof T]: ...}
to define and access its properties:
export type Entries<T> = { [K in keyof T]: [K, T[K]] }[keyof T][];
type E = Entries<{ first: number; second: string }>;
// type E = (["first", number] | ["second", string])[]
You can alternatively employ a distributive conditional type with a helper type alias for functionality:
type EntriesHelper<T, K> = K extends keyof T ? [K, T[K]] : never;
type Entries<T> = Array<EntriesHelper<T, keyof T>>;
type E = Entries<{ first: number; second: string }>;
// type E = (["first", number] | ["second", string])
or opt for a method that utilizes inference in conditional types instead of a separate helper:
type Entries<T> = Array<
keyof T extends infer K ? (K extends keyof T ? [K, T[K]] : never) : never
>;
type E = Entries<{ first: number; second: string }>;
// type E = (["first", number] | ["second", string])[]
While they yield identical results here, nuances may arise regarding optional properties or other edge cases, so proceed cautiously. Best of luck!
Link to code