type TheType = {
PK_1: number;
PK_2: number; // The type may same as other
PK_3: boolean;
PK_4: string;
}
// credits goes to https://stackoverflow.com/a/50375286
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
k: infer I
) => void
? I
: never;
// credits goes to https://github.com/microsoft/TypeScript/issues/13298#issuecomment-468114901
type UnionToOvlds<U> = UnionToIntersection<
U extends any ? (f: U) => void : never
>;
type PopUnion<U> = UnionToOvlds<U> extends (a: infer A) => void ? A : never;
// credit goes to https://stackoverflow.com/questions/53953814/typescript-check-if-a-type-is-a-union#comment-94748994
type IsUnion<T> = [T] extends [UnionToIntersection<T>] ? false : true;
type UnionToArray<T, A extends unknown[] = []> = IsUnion<T> extends true
? UnionToArray<Exclude<T, PopUnion<T>>, [PopUnion<T>, ...A]>
: [T, ...A];
type MapPredicate<Obj, Key> = Key extends keyof Obj ? Obj[Key] : never
// credit goes to https://catchts.com/tuples#map
type Mapped<
Obj,
Arr extends Array<unknown>,
Result extends Array<unknown> = [],
> = Arr extends []
? []
: Arr extends [infer H]
? [...Result, MapPredicate<Obj, H>]
: Arr extends [infer Head, ...infer Tail]
? Mapped<Obj, [...Tail], [...Result, MapPredicate<Obj, Head>]>
: Readonly<Result>;
type Result = Mapped<TheType, UnionToArray<keyof TheType>>; // [number, number, boolean, string]
Playground
Regarding converting union to array you can find more explanation here
Because this answer is a mix of already existing solutions you can find more explanation in appropriate links which I've been left above each helper