Answer the question
In order to leave comments, you need to log in
How to type such a data object?
I have an object with the following structure:
const someData = {
isFetched: false,
pagination: {},
data: // ???
}
isFetched
is always boolean pagination
always like this: (and it may or may not be)type PagePagination = {
totalDocs: number
totalPages: number
page: number
}
data
suggests several possible data types. Their number is very limited (7-8), and they are known in advance. However, when creating an interface for the above, const someData
it's silly to specify something like:interface SomeData = {
isFetched: boolean,
pagination?: PagePagination ,
data: PossibleType1 | PossibleType2 | PossibleType3 | PossibleType4 | PossibleType5 /// ...etc.
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question