The most important thing about this type is the type of the rows property (a single item, not the array type applied to it) returned by the apiCall promise. This type should determine how other functions are on the rest of the type.
Using generics seems like the most reasonable way to handle this, but unfortunately I'm stuck with either manually specifying the generic each time I use this type (which defeats the purpose of relying on apiCall for the type), or just defaulting to any.
What I would like to be able to do is something like this, which means the whole object matching this type will inherit the type of rows[0]:
Even though typescript complains about the second example in my post above, my codebase lit up with some errors which actually helped me.
The below code snippet for example was invalid but got flagged, which again is a good thing:
const updateFn: TableUpdateFn<X> = {
apiCall:... // { rows: Y[], count: number},
selected: (someVar) =>...// do something with someVar, which would be of type X,
...
}
Only problem is that the selected method in the above method errored because someVar became type unknown instead of the type I wanted (type Y)
Suggestion
I've done a lot of research about what I want, and nothing out there seems to reference it. So either what I want is very niche or not possible yet.
I have the following type defined:
The most important thing about this type is the type of the
rowsproperty (a single item, not the array type applied to it) returned by theapiCallpromise. This type should determine how other functions are on the rest of the type.Using generics seems like the most reasonable way to handle this, but unfortunately I'm stuck with either manually specifying the generic each time I use this type (which defeats the purpose of relying on
apiCallfor the type), or just defaulting toany.What I would like to be able to do is something like this, which means the whole object matching this type will inherit the type of
rows[0]:interface self-reference recursion
The text was updated successfully, but these errors were encountered: