I need help with writing types for a function in TypeScript. I have an interface called "Example" with properties 'num' and 'str'. I want to create a function that takes a key (property name from Example) and a new value for that key. However, my current code is not working as expected.
interface Example {
num: number;
str: string;
}
const obj: Example = {
num: 5,
str: '123'
}
const setExampleProp = ({key, value}: {
key: keyof Example;
value: Example[keyof Example];
}) => {
obj[key] = value
}
Error: Type 'string | number' is not assignable to type 'never'. Type 'string' is not assignable to type 'never'.