79329375

Date: 2025-01-04 18:27:40
Score: 1
Natty:
Report link

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.

Reasons:
  • Blacklisted phrase (0.5): Thank you
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: karemont