This is my helper function
type ReturnType = { [k1: string]: { [k2: string]: string } } ;
function createObject(arr: string[]) : ReturnType {
const tempObj : ReturnType = {};
arr.forEach((item) => {
tempObj[item] = {
x: `${item}-x`,
y: `${item}-y`,
z: `${item}-z`,
};
});
return tempObj;
}
Now, I create a new object, using the helper function.
const myObj = createObject(['a', 'b', 'c']);
How do I modify my helper function, so that typescript generates error when the values are not from the given array.
myObj.a.x; // Correct
myObj.something.other; // must give error