My question is regarding a function that utilizes generics and selects data from an object based on a key. Can we use generics inside the type of this object, or do we have to create a separate function for options?
enum Types {
book = 'book',
}
type Base = {
config: any
}
type Options<T> = {
title: string,
config:T
}
// How can we pass a generic "Desired" from getBooks into these options?
const options: Record<Types, Options<??>> = {
book: [{title:'title', config: ['some data']}]
}
const getBook = <Desired extends Base>(type: Types) => {
return options[type]
}
getBook(Types.book)