I am looking to create a simple generic interface for a function that accepts an object's interface, where the first argument is the key of the object and the second argument is another key within that object.
Here is my proposed solution:
type Test<T extends Object, K extends keyof T = keyof T, V extends keyof T[K] = keyof T[K]> = (key: K, key2: V) => void
Object:
const convertFunctionsMap = {
ms: {
h: millisecondsToHours,
s: millisecondsToSeconds,
m: millisecondsToMinutes
},
s: {
h: secondsToHours,
ms: secondsToMilliseconds,
m: secondsToMinutes
},
m: {
ms: minutesToMilliseconds,
s: minutesToSeconds,
h: minutesToHours
},
h: {
ms: hoursToMilliseconds,
s: hoursToSeconds,
m: hoursToMinutes
}
}
However, I encountered the following issue:
https://i.sstatic.net/NR0o0.jpg
CodeSandbox: https://codesandbox.io/s/empty-leaf-cuz51r?file=/src/index.ts