I am attempting to achieve the following:
If the actions property exists, and there are callbacks within the actions properties that return a string, then return X or Y.
The above code is expressed as:
// type MappedType<T> = {
// [K in keyof T]: T[K] extends () => string ? T[K] : never
// }
// it should check if the object has the property actions and also check if properties within actions are callbacks that return a string
type HasStringReturn<Options> = Options extends { actions: { [K in keyof Options]: Options[K] extends () => string ? Options[K] : never } } ? Options: 'Something went wrong';
type StringCallback = {
actions: {
test: () => 'i love owls i really do.'
}
}
type FinalCheck = HasStringReturn<StringCallback>
Currently, it returns "Something went wrong" even though the type is correct. Maybe I am missing something.
I am just trying to check for the existence of actions, and within actions check if the properties are callbacks that return a string. That's pretty much it.
Is this where I have to use infer
or would a generic conditional be sufficient? Curious to know. Thanks.