Encountering the error message
unions can't be used in index signatures, use a mapped object type instead
prompted me to try converting a string literal union (key names of an interface) into a mapped object. I found guidance on how to do this here: https://github.com/microsoft/TypeScript/issues/24220#issuecomment-390063153
Despite trying different approaches, I am still unable to get it working:
const returnObject: {
[index : mappedObjectOfConfigDataKeys] : Partial<ConfigData>
} = {...accumulator};
// Error Message: TS1023: An index signature parameter type must be either 'string' or 'number'.
To address the issue, I attempted the following:
const returnObject: Record<keyof ConfigData, Partial<ConfigData>> = {...accumulator};
This resulted in the error:
Type '{ languageCode?: string | undefined; numberOfRepeats?: number | undefined; projectId?: string | undefined; }' is not assignable to type 'Record<"languageCode" | "numberOfRepeats" | "projectId", Partial<ConfigData>>'.
Types of property 'languageCode' are incompatible.
Type 'string | undefined' is not assignable to type 'Partial<ConfigData>'.
Type 'undefined' is not assignable to type 'Partial<ConfigData>'.ts(2322)
Another attempt was made with the code:
const returnObject: Record<"languageCode" | "numberOfRepeats" | "projectId", Partial<ConfigData>> = {...accumulator};
Which resulted in a similar error:
Type '{ languageCode?: string | undefined; numberOfRepeats?: number | undefined; projectId?: string | undefined; }' is not assignable to type 'Record<"languageCode" | "numberOfRepeats" | "projectId", Partial<ConfigData>>'.
Types of property 'languageCode' are incompatible.
Type 'string | undefined' is not assignable to type 'Partial<ConfigData>'.
Type 'undefined' is not assignable to type 'Partial<ConfigData>'.ts(2322)