Closed bwgjoseph closed 2 years ago
Yeah data is intentional to be given out as opposed to an option
Issue has been created https://github.com/couchbaselabs/node-ottoman/issues/486
@AV25242 Can we fix data
to make it non-optional first before the next beta?
you mean optional ? right now its non-optional
I mean the interface
// should be
export interface ManyResponse {
// note, no ?
data: any[];
match_number: number;
success: number;
errors: StatusExecution[];
}
// instead of
export interface ManyResponse {
data?: any[];
match_number: number;
success: number;
errors: StatusExecution[];
}
Since that, all multi-methods will always return data
, it doesn't make sense to make it optional unless there is case where data
is not being returned
@AV25242 I was testing this with beta.2
but I'm not sure how to take advantage of the recent change to the generic type
So if I don't specify any types, then it gives me any
which is correct
Same thing if I only specify the request type (doc)
So if I pass in the request, response
type (doc, result), it will infer correctly
But then when I tries to access data
, it will infer back to any
Any idea?
@bwgjoseph I am a bit lost here in general. What was this ticket created for and have we addressed whats needed for this ticket or did we derail this one ? :) if so can you assist cleaning this one up probably by opening another ticket and closing this one. This one seems to be overloaded if I am not wrong ? Or this one seems to be closer to the finish line (which I doubt ) ?
I think whatever was done did not resolve this issue, and that's why I'm trying to clarify.
Coming from a developer perspective, it seems like this wasn't done right because it is not inferring the correct type even when I pass in the type
as seen in createMany<AirplaneInterface, AirplaneInterface>
but when I try to use the response
object, the type
is lost and as seen in the last picture, it is now become any
instead of the AirplaneInterface
that I passed in
If done correctly, or at least what I think so, the data
type should auto inferred as AirplaneInterface
instead of any
Based on this PR https://github.com/couchbaselabs/node-ottoman/pull/506, I think something is still not done right that's why it's not inferred correctly. Hence, this issue is still not consider as resolved
@AV25242 @bwgjoseph
@bwgjoseph was right, something was wrong. I declare the generics correctly but I forgot to pass this generic value into inherited components (extends QueryResponse<ManyResponse<T>>
), therefore data was losing the type definition provided.
I already fixed it and will be ready to ship the next release.
Thanks to both of you.
Thanks @gsi-alejandro , @bwgjoseph this should be available in the next release.
Hi @gsi-alejandro,
Not sure if I'm still missing something here, but it still doesn't seem to be able to infer correctly.
This is better now that it inters the interface correctly.
But it's not able to show the fields
I think this should be able to show the fields
hi @bwgjoseph
This issue will be fixed available next release (the fix was already merged into the master branch)
We released Ottoman beta.9 today please verify
Seem to work now
Hi,
Possible to accept generic for ManyQueryResponse?
Notice the
Promise<ManyQueryResponse>
where we can pass return backPromise<ManyQueryResponse<T>>
insteadThis allows better typing like such
So that instead of using
any[]
, we can returnT[]
And the
data
probably don't set it to optional? Seem like the response always return an empty array of data like suchThanks!