I need help figuring out how to define a type for an object that has values dependent on the keys. Check out the code snippet below for a better explanation.
Here is my attempt:
// Given this type
type Mapping = {
"string": string;
"number": number;
"boolean": boolean;
};
// I am attempting to create a type where the keys match those in `Mapping`, but
// the values are functions with the corresponding value of `Mapping` as the first argument.
type Property<K extends keyof Mapping> = Record<K, (value: Mapping[K]) => void>;
type Obj = Partial<Property<keyof Mapping>>;
const a: Obj = {
// Currently, Typescript shows `value` as string | number | boolean.
// My goal is for Typescript to recognize the type of `value` as boolean.
boolean: (value) => {
console.log(value);
}
}