A Complex Union Type

How to get this union type:
type MyType = "x:a" | "x:b" | "x:c" | "y:d" | "y:f" | "y:g";
type MyType = "x:a" | "x:b" | "x:c" | "y:d" | "y:f" | "y:g";
From this object:
const obj = {
x: [
{ value: 'a', checked: false },
{ value: 'b', checked: false },
{ value: 'c', checked: false },
],
y: [
{ value: 'd', checked: false },
{ value: 'f', checked: false },
{ value: 'g', checked: false },
],
} as const;
const obj = {
x: [
{ value: 'a', checked: false },
{ value: 'b', checked: false },
{ value: 'c', checked: false },
],
y: [
{ value: 'd', checked: false },
{ value: 'f', checked: false },
{ value: 'g', checked: false },
],
} as const;
This is the best I could do:
type ObjKey = keyof typeof obj;
type MyType = `${ObjKey}:${(typeof obj)[ObjKey][number]['value']}`;
type ObjKey = keyof typeof obj;
type MyType = `${ObjKey}:${(typeof obj)[ObjKey][number]['value']}`;
But it will combine both x and y with a..g
2 Replies
Want results from more Discord servers?
Add your server