I have a reusable function that can be used on various properties of a custom type. Here's an example:
interface MyType {
prop1: string;
prop2: number;
}
type MyTypeKey = keyof MyType;
const testValue = (
obj: MyType,
property: MyTypeKey,
value: any, // <-- what type should go here?
) => {
if (obj[property] === value) {
console.log("do something");
}
}
testValue({prop1: "a", prop2: 1}, "prop1", "okay"); // should be okay
testValue({prop1: "a", prop2: 1}, "prop2", "oops"); // should be error
However, I'm unsure about the type of the property value. Can anyone guide me on how to handle this?
(I am new to javascript/typescript, so please excuse any small errors or suboptimal practices)