-
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.
feat(@remix-run/cloudflare,@remix-run/deno,@remix-run/node): `Seriali…
…zeFrom` utility for loader and action type inference (#4013) * docs(@remix-run/react): reunite `useLoaderData` with its jsdoc * refactor(@remix-run/react): factor out `SerializeType` * refactor(@remix-run/react): singularize union types convention is to use plurals for collections (e.g. arrays), not for unions * refactor(@remix-run/react): properly constrain objects in typescript arrays are technically `object`s, so we need something more specific. `Record<PropertyKey, unknown>` should match any object, but not match arrays. * refactor(@remix-run/react): remove redundant "Type" suffix from typescript utilities * refactor(@remix-run/react): rename `UndefinedOptionals` to `UndefinedToOptional` more obvious that this _converts_ `undefined` unions to optionals * refactor(@remix-run/react): factor out tuple serialization into type utility and to be consistent with `SerializeObject` * fix(@remix-run/react): `Serialize<any>` should return `any` * fix(@remix-run/react): serialize classes and provide comments to explain what tuples are and how `object` matches classes * style(@remix-run/react): do not auto-format typescript ternaries 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. * refactor(@remix-run/react): move serialize type utilities into their own module * refactor(@remix-run/react): inline `DataOrFunction` type since its only used once * refactor(@remix-run/react): rename `UseDataFunctionReturn` to `SerializeFrom` since the type can be used without `useLoaderData` or `useActionData` and just returns the JSON serialized data from a loader or action * chore(lint): ignore eslint warning about unused typescript generic that _is_ being used * docs(@remix-run/react): jsdoc for `SerializeFrom` * chore(@remix-run/react): add comment explaining `IsAny` implementation * refactor(serialize): move serialize type utilities into `@remix-run/server-runtime` * feat(@remix-run/deno,@remix-run/cloudflare,@remix-run/node): export `SerializeFrom` type utility also, sync re-exports from `@remix-run/server-runtime` * Create neat-beds-unite.md
- Loading branch information
Showing
11 changed files
with
147 additions
and
106 deletions.
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,20 @@ | ||
--- | ||
"remix": minor | ||
"@remix-run/cloudflare": minor | ||
"@remix-run/deno": minor | ||
"@remix-run/node": minor | ||
"@remix-run/react": minor | ||
"@remix-run/serve": minor | ||
"@remix-run/server-runtime": minor | ||
--- | ||
|
||
Each runtime package (@remix-run/cloudflare,@remix-run/deno,@remix-run/node) now exports `SerializeFrom`, which is used to | ||
infer the JSON-serialized return type of loaders and actions. | ||
|
||
Example: | ||
```ts | ||
type MyLoaderData = SerializeFrom<typeof loader> | ||
type MyActionData = SerializeFrom<typeof action> | ||
``` | ||
This is what `useLoaderData<typeof loader>` and `useActionData<typeof action>` use under-the-hood. |
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
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
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
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
Oops, something went wrong.