I am looking to extract the type of object keys. Below is a generic function for objects with keys as strings:
type GenericInput = {
[key:string]: {value:string,type:HTMLInputTypeAttribute,placeholder:string,min?:number,max?:number,required?:boolean, error?:string}
}
function PageContent(props: { children: React.ReactNode,inputs:GenericInput,getData:(data)=>void}) {
const [query,setQuery] = useState<GenericInput>(props.inputs)
const formKeys = Object.keys(query)
getData(query)
}
However, I aim to pass data in a way that returns an object literal of key types. This would enable IDE auto-completion for keys. Essentially, I want to convert these keys into a literal type.
My ideal scenario would look something like this:
type GenericInput = {
[key: Object.keys(query)]:{value:string,type:HTMLInputTypeAttribute,placeholder:string,min?:number,max?:number,required?:boolean, error?:string}
}