Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(remix-server-runtime): disallow incompatible return types of TypedResponse #4734

Merged
merged 6 commits into from Dec 2, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions .changeset/light-sheep-give.md
@@ -0,0 +1,26 @@
---
"remix": patch
"@remix-run/serve": patch
"@remix-run/server-runtime": 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:

```ts
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`.
dabdine marked this conversation as resolved.
Show resolved Hide resolved

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> }`.