I’ve just also run into a similar problem as Error: Field value has a type which is less general than the (defined) scoped polymorphic type writing bindings for react-router v6:
This type definition for a RouteObject:
type rec t = {
caseSensitive?: bool,
children?: array<t>,
element?: React.element,
index?: bool,
path?: string,
loader?: 'data. unit => promise<'data>,
action?: unknown, // TODO
errorElement?: React.element,
hydrateFallbackElement?: React.element,
@as("Component") component?: React.component<{}>,
@as("ErrorBoundary") errorBoundary?: React.component<{}>,
// handle?: unknown
shouldRevalidate?: bool,
@as("lazy") lazy_?: unit => promise<unknown>,
}
When actually attempting to use it gives this type error
60 │ caseSensitive: true,
61 │ element: <Settings />,
62 │ loader: async (type data, ()) => {
63 │ let response = await Fetch.fetch("/api/settings", {method: #GET})
. │ ...
66 │ json
67 │ },
68 │ }
69 │
This has type: unit => promise<Js.Json.t>
But it's expected to have type: 'data. unit => promise<'data>
Now I could reach for the GADT-style of binding the route objects, and in some respects that makes sense for the union type. But does anyone know how you could type-annotate this to use this feature? I can imagine a good number of Javascript APIs that’d become a lot less verbose to use with this–presuming you don’t have to use @send bindings to get polymorphic behavior on a record type with a function.