Skip to content

Commit d758e05

Browse files
committed
Merge branch 'main' into pr/duducpp/13467
2 parents 4e229e0 + 84c0293 commit d758e05

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

documentation/docs/98-reference/54-types.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ title: Types
77
The `RequestHandler` and `Load` types both accept a `Params` argument allowing you to type the `params` object. For example this endpoint expects `foo`, `bar` and `baz` params:
88

99
```js
10-
/// file: src/routes/[foo]/[bar]/[baz]/+page.server.js
10+
/// file: src/routes/[foo]/[bar]/[baz]/+server.js
1111
// @errors: 2355 2322 1360
1212
/** @type {import('@sveltejs/kit').RequestHandler<{
1313
foo: string;
@@ -34,14 +34,14 @@ type RouteParams = {
3434
baz: string;
3535
};
3636

37-
export type PageServerLoad = Kit.ServerLoad<RouteParams>;
37+
export type RequestHandler = Kit.RequestHandler<RouteParams>;
3838
export type PageLoad = Kit.Load<RouteParams>;
3939
```
4040

4141
These files can be imported into your endpoints and pages as siblings, thanks to the [`rootDirs`](https://www.typescriptlang.org/tsconfig#rootDirs) option in your TypeScript configuration:
4242

4343
```js
44-
/// file: src/routes/[foo]/[bar]/[baz]/+page.server.js
44+
/// file: src/routes/[foo]/[bar]/[baz]/+server.js
4545
// @filename: $types.d.ts
4646
import type * as Kit from '@sveltejs/kit';
4747

@@ -51,12 +51,12 @@ type RouteParams = {
5151
baz: string;
5252
}
5353

54-
export type PageServerLoad = Kit.ServerLoad<RouteParams>;
54+
export type RequestHandler = Kit.RequestHandler<RouteParams>;
5555

5656
// @filename: index.js
57-
// @errors: 2355
57+
// @errors: 2355 2322
5858
// ---cut---
59-
/** @type {import('./$types').PageServerLoad} */
59+
/** @type {import('./$types').RequestHandler} */
6060
export async function GET({ params }) {
6161
// ...
6262
}
@@ -84,7 +84,9 @@ export async function load({ params, fetch }) {
8484
}
8585
```
8686

87-
The return types of the load functions are then available through the `$types` module as `PageData` and `LayoutData` respectively, while the union of the return values of all `Actions` is available as `ActionData`. Starting with version 2.16.0, two additional helper types are provided. `PageProps` defines `data: PageData`, as well as `form: ActionData`, when there are actions defined. `LayoutProps` defines `data: LayoutData`, as well as `children: Snippet`:
87+
The return types of the load functions are then available through the `$types` module as `PageData` and `LayoutData` respectively, while the union of the return values of all `Actions` is available as `ActionData`.
88+
89+
Starting with version 2.16.0, two additional helper types are provided: `PageProps` defines `data: PageData`, as well as `form: ActionData`, when there are actions defined, while `LayoutProps` defines `data: LayoutData`, as well as `children: Snippet`.
8890

8991
```svelte
9092
<!--- file: src/routes/+page.svelte --->

0 commit comments

Comments
 (0)