-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix 4199: TypedResponse allows incompatible types (#4734)
* Fixes #4199: Do not allow assignment of incompatible TypedResponses * Add myself to contributors.yml * Create light-sheep-give.md * slight changeset tweak * additional changeset tweaks Co-authored-by: Pedro Cattori <[email protected]>
- Loading branch information
Showing
4 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 not show an error even though `42` is clearly not a `string`. | ||
|
||
This happens because `json` returns a `TypedResponse<string>`, | ||
but because `TypedReponse<string>` was previously just `Response & { json: () => Promise<string> }` | ||
and `Response` already defines `{ json: () => Promise<any> }`, 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> }`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -452,3 +452,4 @@ | |
- zachdtaylor | ||
- zainfathoni | ||
- zhe | ||
- dabdine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters