I want to create a type that combines the values of two properties of one object in an array.
My solution so far, looks like this:
const CONFIGS = [
{ section: "a", name: "1" },
{ section: "b", name: "2" },
] as const;
type ConfigSections<I extends number> = typeof CONFIGS[I]["section"];
type ConfigSectionEntryName<I extends number> = typeof CONFIGS[I]["name"];
// Allows all permutations of section and name: "a_1" | "a_2" | "b_1" | "b_2" :(
// I only want "a_1" | "b_2"
type CompleteConfigName<I extends number> =
`${ConfigSections<I>}_${ConfigSectionEntryName<I>}`;
But in the type CompleteConfigName<I extends number> the I seems to allow any number, as the type resolves to "a_1" | "a_2" | "b_1" | "b_2".
But I want to enforce a specific index number I, so that the type results to "a_1" | "b_2"