After some trials, my workaround was to use the following:
const obj = {
a: 1,
b: 2,
c: 3
}
type Primitive<T = string | number> =
T extends string ? string & {}
: T extends number ? number & {}
: never;
type KeysA<O> = keyof O | Primitive;
const a: KeysA<typeof obj> = 'a';
const b: KeysA<typeof obj> = 'custom';
const c: KeysA<typeof obj> = 123;
type KeysB<O, T = string> = keyof O | Primitive<T>;
const d: KeysB<typeof obj> = 'a';
const e: KeysB<typeof obj> = 'custom';
const f: KeysB<typeof obj> = 123;
Other workarounds are still welcome, Thank you.