-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
opt-in type inference for single-fetch
- Loading branch information
Showing
3 changed files
with
67 additions
and
0 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,15 @@ | ||
--- | ||
"@remix-run/react": patch | ||
--- | ||
|
||
Opt-in types for single-fetch | ||
|
||
In your `tsconfig.json`: | ||
|
||
```json | ||
{ | ||
"include": [ | ||
"./node_modules/@remix-run/react/future/single-fetch.d.ts" | ||
] | ||
} | ||
``` |
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,51 @@ | ||
import type { AppLoadContext } from "@remix-run/server-runtime"; | ||
|
||
type Serializable = | ||
| undefined | ||
| null | ||
| boolean | ||
| string | ||
| symbol | ||
| number | ||
| Array<Serializable> | ||
| { [key: PropertyKey]: Serializable } | ||
| bigint | ||
| Date | ||
| URL | ||
| RegExp | ||
| Error | ||
| Map<Serializable, Serializable> | ||
| Set<Serializable> | ||
| Promise<Serializable>; | ||
|
||
type Params<Key extends string = string> = { | ||
readonly [key in Key]: string | undefined; | ||
}; | ||
|
||
type ResponseStub = { | ||
status?: number; | ||
headers: Headers; | ||
}; | ||
|
||
type DataFunction = ( | ||
args: { | ||
request: Request; | ||
params: Params; | ||
context: AppLoadContext; | ||
response: ResponseStub; | ||
}, | ||
handlerCtx?: unknown | ||
) => Serializable; | ||
|
||
type Loader = DataFunction & { hydrate?: boolean }; | ||
type Action = DataFunction; | ||
|
||
declare module "@remix-run/react" { | ||
export function useLoaderData<T>(): T extends Loader | ||
? Awaited<ReturnType<T>> | ||
: never; | ||
|
||
export function useActionData<T>(): T extends Action | ||
? Awaited<ReturnType<T>> | ||
: never; | ||
} |
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