I have an object that is types as PType
and looks like this:
import { path } from 'ramda';
const obj: PType = {
prop1: {
val1: "foo",
},
prop2: {
foo: "bar",
}
}
Now, I also created a function to get specific values from the object like so:
export const getProps = (keys: [keyof PType, string]) => path(['obj', ...keys]
And I am using it as such:
export const prop1 = (value: keyof PType['prop1']) => getProps(['prop1', `${value}`]);
So the idea is that value
in the prop1
function is types as keyof PType['prop1']
but types as string
inside the getProps
function.
I tried to fix the string
typing by using:
export const getProps = (keys: [keyof PType, keyof PType[keyof PType]) => {...}
but that will not work and TS will not let me do that.
I'd love to pass in a dynamic type there instead of having just a string
definition on that place.
I assume there's something like a generic type definition or map but I haven't found a solution for it yet.