I am new to using React with typescript and I recently came across the following issue. It is my understanding that if I am declaring my initial state as an empty array like so:
const [todos, setTodos] = useState<{ id: string; text: string }[]>([])
I need to provide typescript with an interface of what the array will eventually look like. hence the useState<{ id: string; text: string }[]>
. What I am curious about is the use case of me fetching data from an api, etc. and the schema is very large or the values are dynamic. How do I go about letting typescript know what my empty array will eventually be set to. If i'm fetching an extremely large array of objects, I feel as though it wouldn't be efficient to have to go through and outline each key-value pair. Or if the data is dynamic how could I possibly outline the schema?