remix | @remix-run/serve | @remix-run/server-runtime |
---|---|---|
patch |
patch |
patch |
Fix TypedResponse
so that Typescript correctly shows errors for incompatible types in loaders and actions.
Previously, when the return type of a loader or action was explicitly set to TypedResponse<SomeType>
,
Typescript would not show errors when the loader or action returned an incompatible type.
For example:
export const action = async (args: ActionArgs): Promise<TypedResponse<string>> => {
return json(42);
};
In this case, Typescript would now show an error even though 42
is clearly not a string
.
In this case, happens because json
returns a TypedResponse<string>
,
but because TypedReponse<string>
is just Response & { json: () => Promise<string> }
and Response
already defines { json: () => Promise<any> }
, then type erasure caused Promise<any>
to be used for 42
.
To fix this, we explicitly omit the Response
's json
property before intersecting with { json: () => Promise<T> }
.