Are the Result<T, Error> type definitions wrong?
tobias-tengler opened this issue · 5 comments
I wanted to play around with @catch
and noticed that the Flow / TypeScript types and the compiler generated errors passed to the Result type don't make much sense.
The compiler will generate the following code:
export type FooQuery$data = {|
+me: Result<?{|
+firstName: ?string,
+lastName: ?string,
|}, $ReadOnlyArray<mixed>>,
|};
so the error type is $ReadOnlyArray<mixed>
.
The type definitions in relay-runtime define the errors field on the ErrorResult
as a $ReadOnlyArray<Error>
:
https://github.com/facebook/relay/blob/e357063c26d0aaf0a5027ba591138ad172cd103f/packages/relay-runtime/experimental.js#L46C2-L55C67
So you'd end up with the ErrorResult.errors
being Array<Array<Error>>
. This doesn't seem right to me?
Maybe this is a bug where we've used a global type Error
as the name of a type generic?
@captbaritone I think @tobias-tengler hunch might be correct. That the generated FooQuery$data here should be
export type FooQuery$data = {|
+me: Result<?{|
+firstName: ?string,
+lastName: ?string,
|}, mixed,
|};
@captbaritone yup
I see, I missed the point. Array<Array<Error>>
. Yeah, looks like a bug in the types.
Fixed by 9571d80