-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Add type deprecations for types now in React Router #5679
Changes from 6 commits
c2eb289
94f9bcf
f6d4092
10eec8f
4d4a84f
6b184f2
ac94a7a
503cc2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@remix-run/react": patch | ||
"@remix-run/server-runtime": patch | ||
--- | ||
|
||
Add type deprecations for types now in React Router |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { | ||
defer as routerDefer, | ||
json as routerJson, | ||
redirect as routerRedirect, | ||
type UNSAFE_DeferredData as DeferredData, | ||
type TrackedPromise, | ||
} from "@remix-run/router"; | ||
|
@@ -23,8 +25,6 @@ export type JsonFunction = <Data extends unknown>( | |
init?: number | ResponseInit | ||
) => TypedResponse<Data>; | ||
|
||
// must be a type since this is a subtype of response | ||
// interfaces must conform to the types they extend | ||
export type TypedResponse<T extends unknown = unknown> = Omit< | ||
Response, | ||
"json" | ||
|
@@ -39,37 +39,16 @@ export type TypedResponse<T extends unknown = unknown> = Omit< | |
* @see https://remix.run/utils/json | ||
*/ | ||
export const json: JsonFunction = (data, init = {}) => { | ||
let responseInit = typeof init === "number" ? { status: init } : init; | ||
|
||
let headers = new Headers(responseInit.headers); | ||
if (!headers.has("Content-Type")) { | ||
headers.set("Content-Type", "application/json; charset=utf-8"); | ||
} | ||
|
||
return new Response(JSON.stringify(data), { | ||
...responseInit, | ||
headers, | ||
}); | ||
return routerJson(data, init); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use router methods directly, but preserve typecasting on the returned values |
||
}; | ||
|
||
/** | ||
* This is a shortcut for creating `application/json` responses. Converts `data` | ||
* to JSON and sets the `Content-Type` header. | ||
* This is a shortcut for creating Remix deferred responses | ||
* | ||
* @see https://remix.run/api/remix#json | ||
* @see https://remix.run/docs/utils/defer | ||
*/ | ||
export const defer: DeferFunction = (data, init = {}) => { | ||
let responseInit = typeof init === "number" ? { status: init } : init; | ||
|
||
let headers = new Headers(responseInit.headers); | ||
if (!headers.has("Content-Type")) { | ||
headers.set("Content-Type", "application/json; charset=utf-8"); | ||
} | ||
Comment on lines
-64
to
-67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jacob-ebey I think this was only here from a copy/paste and eventually gets overwritten with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That should be fine. |
||
|
||
return routerDefer(data, { | ||
...responseInit, | ||
headers, | ||
}) as TypedDeferredData<typeof data>; | ||
return routerDefer(data, init) as TypedDeferredData<typeof data>; | ||
}; | ||
|
||
export type RedirectFunction = ( | ||
|
@@ -84,20 +63,7 @@ export type RedirectFunction = ( | |
* @see https://remix.run/utils/redirect | ||
*/ | ||
export const redirect: RedirectFunction = (url, init = 302) => { | ||
let responseInit = init; | ||
if (typeof responseInit === "number") { | ||
responseInit = { status: responseInit }; | ||
} else if (typeof responseInit.status === "undefined") { | ||
responseInit.status = 302; | ||
} | ||
|
||
let headers = new Headers(responseInit.headers); | ||
headers.set("Location", url); | ||
|
||
return new Response(null, { | ||
...responseInit, | ||
headers, | ||
}) as TypedResponse<never>; | ||
return routerRedirect(url, init) as TypedResponse<never>; | ||
}; | ||
|
||
export function isDeferredData(value: any): value is DeferredData { | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer used