Skip to content

Commit

Permalink
Fix types for unstable_data (#9811)
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 authored Jul 31, 2024
1 parent ce01ef1 commit c8f308f
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 34 deletions.
5 changes: 5 additions & 0 deletions .changeset/mighty-needles-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/react": patch
---

[REMOVE] Fix typings for unstable_data and useLoaderData
2 changes: 1 addition & 1 deletion integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@remix-run/dev": "workspace:*",
"@remix-run/express": "workspace:*",
"@remix-run/node": "workspace:*",
"@remix-run/router": "1.19.0-pre.0",
"@remix-run/router": "1.19.0-pre.1",
"@remix-run/server-runtime": "workspace:*",
"@types/express": "^4.17.9",
"@vanilla-extract/css": "^1.10.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@mdx-js/mdx": "^2.3.0",
"@npmcli/package-json": "^4.0.1",
"@remix-run/node": "workspace:*",
"@remix-run/router": "1.19.0-pre.0",
"@remix-run/router": "1.19.0-pre.1",
"@remix-run/server-runtime": "workspace:*",
"@types/mdx": "^2.0.5",
"@vanilla-extract/integration": "^6.2.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/remix-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
"tsc": "tsc"
},
"dependencies": {
"@remix-run/router": "1.19.0-pre.0",
"@remix-run/router": "1.19.0-pre.1",
"@remix-run/server-runtime": "workspace:*",
"react-router": "6.26.0-pre.0",
"react-router-dom": "6.26.0-pre.0",
"react-router": "6.26.0-pre.1",
"react-router-dom": "6.26.0-pre.1",
"turbo-stream": "2.2.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-server-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"tsc": "tsc"
},
"dependencies": {
"@remix-run/router": "1.19.0-pre.0",
"@remix-run/router": "1.19.0-pre.1",
"@types/cookie": "^0.6.0",
"@web3-storage/multipart-parser": "^1.0.0",
"cookie": "^0.6.0",
Expand Down
8 changes: 7 additions & 1 deletion packages/remix-server-runtime/single-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {
StaticHandler,
unstable_DataStrategyFunctionArgs as DataStrategyFunctionArgs,
unstable_DataStrategyFunction as DataStrategyFunction,
UNSAFE_DataWithResponseInit as DataWithResponseInit,
} from "@remix-run/router";
import {
isRouteErrorResponse,
Expand Down Expand Up @@ -335,7 +336,10 @@ export function encodeViaTurboStream(
});
}

export function data(value: Serializable, init?: number | ResponseInit) {
export function data<D extends Serializable>(
value: D,
init?: number | ResponseInit
) {
return routerData(value, init);
}

Expand All @@ -361,6 +365,7 @@ type Serializable =

type DataFunctionReturnValue =
| Serializable
| DataWithResponseInit<Serializable>
| TypedDeferredData<Record<string, unknown>>
| TypedResponse<Record<string, unknown>>;

Expand All @@ -372,6 +377,7 @@ type DataFunctionReturnValue =
export type Serialize<T extends Loader | Action> =
Awaited<ReturnType<T>> extends TypedDeferredData<infer D> ? D :
Awaited<ReturnType<T>> extends TypedResponse<Record<string, unknown>> ? SerializeFrom<T> :
Awaited<ReturnType<T>> extends DataWithResponseInit<infer D> ? D :
Awaited<ReturnType<T>>;

export type Loader = (
Expand Down
4 changes: 2 additions & 2 deletions packages/remix-testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"dependencies": {
"@remix-run/node": "workspace:*",
"@remix-run/react": "workspace:*",
"@remix-run/router": "1.19.0-pre.0",
"react-router-dom": "6.26.0-pre.0"
"@remix-run/router": "1.19.0-pre.1",
"react-router-dom": "6.26.0-pre.1"
},
"devDependencies": {
"@remix-run/server-runtime": "workspace:*",
Expand Down
50 changes: 25 additions & 25 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c8f308f

Please sign in to comment.