-
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
feat(@remix-run/cloudflare,@remix-run/deno,@remix-run/node): SerializeFrom
utility for loader and action type inference
#4013
Conversation
🦋 Changeset detectedLatest commit: 65aceb4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
bed12e9
to
c512e1d
Compare
c512e1d
to
377512a
Compare
|
||
function isEqual<A, B>( | ||
arg: A extends B ? (B extends A ? true : false) : false | ||
): void {} | ||
|
||
// not sure why `eslint` thinks the `T` generic is not used... | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
type LoaderData<T> = ReturnType<typeof useLoaderData<T>>; |
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.
note: this test is for testing useLoaderData
's types, so we actually grab types from useLoaderData
instead of assuming its using UseDataFunctionReturn
or SerializeFrom
.
7e2556c
to
fc97ee4
Compare
SerializeFrom
utility for loader and action type inferenceSerializeFrom
utility for loader and action type inference
@@ -32,7 +32,6 @@ export type { | |||
CookieParseOptions, | |||
CookieSerializeOptions, | |||
CookieSignatureOptions, | |||
CreateRequestHandlerFunction, |
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.
CreateRequestHandlerFunction
is a utility for authoring Remix runtime packages and was incorrectly re-exported before.
@@ -28,7 +28,6 @@ export type { | |||
IsSessionFunction, | |||
JsonFunction, | |||
RedirectFunction, | |||
TypedResponse, |
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.
The interface
section of exports is for types related to values/functions that should be exported by every server runtime pkg. We use the fetch API for request/response, so we don't export our own request/response implementations from server runtime pkgs.
Therefore, TypedResponse
should not be considered part of the server runtime interface.
TBH the distinction between "interface" and "re-export" is subtle and I'd much prefer to not need re-exports at all once we have a pkg for exporting runtime-agnostic stuff.
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.
Just one note on the changeset, otherwise looks good!
acecb4c
to
bb68c13
Compare
convention is to use plurals for collections (e.g. arrays), not for unions
arrays are technically `object`s, so we need something more specific. `Record<PropertyKey, unknown>` should match any object, but not match arrays.
…ToOptional` more obvious that this _converts_ `undefined` unions to optionals
…utility and to be consistent with `SerializeObject`
and provide comments to explain what tuples are and how `object` matches classes
makes each line in the type definition independent of other lines. more readable and easier to comment/uncomment specific conditions. plus less git noise when adding/removing/reordering conditions.
…izeFrom` since the type can be used without `useLoaderData` or `useActionData` and just returns the JSON serialized data from a loader or action
…at _is_ being used
…SerializeFrom` type utility also, sync re-exports from `@remix-run/server-runtime`
bb68c13
to
65aceb4
Compare
Renamed internal
UseDataFunctionReturn
type toSerializeFrom
since its can be used withoutuseLoaderData
anduseActionData
. A bunch of small type cleanups + bug fixes. Moved serialize type utilities to@remix-run/server-runtime
and re-exportingSerializeFrom
andTypedResponse
from each runtime pkg.Testing Strategy:
@remix-run/react
@remix-run/server-runtime
and@remix-run/node
, importedSerializedFrom
from@remix-run/node
, and got the correct type in VS Code