From b8d26bd3a640adf2ee4ed1854e1cc78e396a050e Mon Sep 17 00:00:00 2001 From: Bao Dang Date: Wed, 6 Nov 2024 11:19:29 -0500 Subject: [PATCH 1/6] Add 'PageProps' to '$./types' + Documentation --- .changeset/spotty-jars-kiss.md | 5 +++++ documentation/docs/02-runes/05-$props.md | 28 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 .changeset/spotty-jars-kiss.md create mode 100644 documentation/docs/02-runes/05-$props.md diff --git a/.changeset/spotty-jars-kiss.md b/.changeset/spotty-jars-kiss.md new file mode 100644 index 000000000000..da2aaa6bd6b6 --- /dev/null +++ b/.changeset/spotty-jars-kiss.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': major +--- + +Add 'PageProps' to './$types' diff --git a/documentation/docs/02-runes/05-$props.md b/documentation/docs/02-runes/05-$props.md new file mode 100644 index 000000000000..1d8073b39b22 --- /dev/null +++ b/documentation/docs/02-runes/05-$props.md @@ -0,0 +1,28 @@ + +### PageProps + +For defining types of `$props` rune in `page.svelte`, you would normally do the following + +```svelte + + +``` + +If you don't want to write this for every page, you can do the following instead + +```svelte + + +``` \ No newline at end of file From a1951310ffd945eebac6ddd2d4b5375f1d43453d Mon Sep 17 00:00:00 2001 From: Bao Dang Date: Wed, 6 Nov 2024 11:25:51 -0500 Subject: [PATCH 2/6] Edit tabs in documentation --- documentation/docs/02-runes/05-$props.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/docs/02-runes/05-$props.md b/documentation/docs/02-runes/05-$props.md index 1d8073b39b22..ef7039f4ae80 100644 --- a/documentation/docs/02-runes/05-$props.md +++ b/documentation/docs/02-runes/05-$props.md @@ -21,7 +21,7 @@ If you don't want to write this for every page, you can do the following instead ```svelte From 232a02d787394ba4f9153204b731966d729a4af0 Mon Sep 17 00:00:00 2001 From: Bao Dang Date: Mon, 11 Nov 2024 22:48:57 -0500 Subject: [PATCH 3/6] Add 'PageProps' to index.d.ts in kit --- packages/kit/types/index.d.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index 237b3e3ff57e..0d4e25914511 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -2253,6 +2253,7 @@ declare module '$app/stores' { * // interface Error {} * // interface Locals {} * // interface PageData {} + * // interface PageProps {} * // interface PageState {} * // interface Platform {} * } @@ -2286,6 +2287,13 @@ declare namespace App { */ export interface PageData {} + /** + * Defines the reusable shape for [$props()](https://svelte.dev/docs/svelte/$props#Type-safety) for `+page.svelte` specifically + */ + export interface PageProps { + data: PageData; + } + /** * The shape of the `$page.state` object, which can be manipulated using the [`pushState`](https://svelte.dev/docs/kit/$app-navigation#pushState) and [`replaceState`](https://svelte.dev/docs/kit/$app-navigation#replaceState) functions from `$app/navigation`. */ From 15e7d1b186155687909ff99a4f67149d5fe093b4 Mon Sep 17 00:00:00 2001 From: Bao Dang Date: Mon, 11 Nov 2024 22:53:59 -0500 Subject: [PATCH 4/6] Regenerate types --- packages/kit/types/index.d.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index 0d4e25914511..237b3e3ff57e 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -2253,7 +2253,6 @@ declare module '$app/stores' { * // interface Error {} * // interface Locals {} * // interface PageData {} - * // interface PageProps {} * // interface PageState {} * // interface Platform {} * } @@ -2287,13 +2286,6 @@ declare namespace App { */ export interface PageData {} - /** - * Defines the reusable shape for [$props()](https://svelte.dev/docs/svelte/$props#Type-safety) for `+page.svelte` specifically - */ - export interface PageProps { - data: PageData; - } - /** * The shape of the `$page.state` object, which can be manipulated using the [`pushState`](https://svelte.dev/docs/kit/$app-navigation#pushState) and [`replaceState`](https://svelte.dev/docs/kit/$app-navigation#replaceState) functions from `$app/navigation`. */ From 6fa3692d819bb3112f6087b88aaae55721296394 Mon Sep 17 00:00:00 2001 From: Bao Dang Date: Wed, 13 Nov 2024 10:15:39 -0500 Subject: [PATCH 5/6] Added 'PageProps' types in the correct file thanks to @eltigerchino --- packages/kit/src/types/ambient.d.ts | 8 ++++++++ packages/kit/types/index.d.ts | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/packages/kit/src/types/ambient.d.ts b/packages/kit/src/types/ambient.d.ts index 496fc537cf4d..9f4bfb7cdddd 100644 --- a/packages/kit/src/types/ambient.d.ts +++ b/packages/kit/src/types/ambient.d.ts @@ -7,6 +7,7 @@ * // interface Error {} * // interface Locals {} * // interface PageData {} + * // interface PageProps {} * // interface PageState {} * // interface Platform {} * } @@ -40,6 +41,13 @@ declare namespace App { */ export interface PageData {} + /** + * Defines the reusable shape for [$props()](https://svelte.dev/docs/svelte/$props#Type-safety) for `+page.svelte` specifically + */ + export interface PageProps { + data: PageData; + } + /** * The shape of the `$page.state` object, which can be manipulated using the [`pushState`](https://svelte.dev/docs/kit/$app-navigation#pushState) and [`replaceState`](https://svelte.dev/docs/kit/$app-navigation#replaceState) functions from `$app/navigation`. */ diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index 237b3e3ff57e..0d4e25914511 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -2253,6 +2253,7 @@ declare module '$app/stores' { * // interface Error {} * // interface Locals {} * // interface PageData {} + * // interface PageProps {} * // interface PageState {} * // interface Platform {} * } @@ -2286,6 +2287,13 @@ declare namespace App { */ export interface PageData {} + /** + * Defines the reusable shape for [$props()](https://svelte.dev/docs/svelte/$props#Type-safety) for `+page.svelte` specifically + */ + export interface PageProps { + data: PageData; + } + /** * The shape of the `$page.state` object, which can be manipulated using the [`pushState`](https://svelte.dev/docs/kit/$app-navigation#pushState) and [`replaceState`](https://svelte.dev/docs/kit/$app-navigation#replaceState) functions from `$app/navigation`. */ From 4ad2dc8f641e533e3427502039822638c05e84a4 Mon Sep 17 00:00:00 2001 From: Bao Dang Date: Wed, 13 Nov 2024 21:41:39 -0500 Subject: [PATCH 6/6] Generate 'PageProps' and 'LayoutProps' for each route --- packages/kit/src/core/sync/write_types/index.js | 6 ++++++ packages/kit/src/types/ambient.d.ts | 8 -------- packages/kit/types/index.d.ts | 8 -------- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/packages/kit/src/core/sync/write_types/index.js b/packages/kit/src/core/sync/write_types/index.js index 42728feaf187..66a7d325a692 100644 --- a/packages/kit/src/core/sync/write_types/index.js +++ b/packages/kit/src/core/sync/write_types/index.js @@ -465,6 +465,12 @@ function process_node(node, outdir, is_page, proxies, all_pages_have_load = true exports.push(`export type ${prefix}Data = ${data};`); + exports.push( + `export type ${prefix}Props = { data: ${prefix}Data; ${ + node.server && is_page ? 'form: ActionData; ' : '' + }};` + ); + return { declarations, exports, proxies }; /** diff --git a/packages/kit/src/types/ambient.d.ts b/packages/kit/src/types/ambient.d.ts index 9f4bfb7cdddd..496fc537cf4d 100644 --- a/packages/kit/src/types/ambient.d.ts +++ b/packages/kit/src/types/ambient.d.ts @@ -7,7 +7,6 @@ * // interface Error {} * // interface Locals {} * // interface PageData {} - * // interface PageProps {} * // interface PageState {} * // interface Platform {} * } @@ -41,13 +40,6 @@ declare namespace App { */ export interface PageData {} - /** - * Defines the reusable shape for [$props()](https://svelte.dev/docs/svelte/$props#Type-safety) for `+page.svelte` specifically - */ - export interface PageProps { - data: PageData; - } - /** * The shape of the `$page.state` object, which can be manipulated using the [`pushState`](https://svelte.dev/docs/kit/$app-navigation#pushState) and [`replaceState`](https://svelte.dev/docs/kit/$app-navigation#replaceState) functions from `$app/navigation`. */ diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index 0d4e25914511..237b3e3ff57e 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -2253,7 +2253,6 @@ declare module '$app/stores' { * // interface Error {} * // interface Locals {} * // interface PageData {} - * // interface PageProps {} * // interface PageState {} * // interface Platform {} * } @@ -2287,13 +2286,6 @@ declare namespace App { */ export interface PageData {} - /** - * Defines the reusable shape for [$props()](https://svelte.dev/docs/svelte/$props#Type-safety) for `+page.svelte` specifically - */ - export interface PageProps { - data: PageData; - } - /** * The shape of the `$page.state` object, which can be manipulated using the [`pushState`](https://svelte.dev/docs/kit/$app-navigation#pushState) and [`replaceState`](https://svelte.dev/docs/kit/$app-navigation#replaceState) functions from `$app/navigation`. */