Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/brave-canyons-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': minor
---

feat: add `ErrorProps` to generated types
15 changes: 5 additions & 10 deletions packages/kit/src/core/sync/write_types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ function update_types(config, routes, route, root, to_delete = new Set()) {
'type OptionalUnion<U extends Record<string, any>, A extends keyof U = U extends U ? keyof U : never> = U extends unknown ? { [P in Exclude<A, keyof U>]?: never } & U : never;',

// Re-export `Snapshot` from @sveltejs/kit — in future we could use this to infer <T> from the return type of `snapshot.capture`
'export type Snapshot<T = any> = Kit.Snapshot<T>;'
'export type Snapshot<T = any> = Kit.Snapshot<T>;',

'export type ErrorProps = { error: App.Error };'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to make it only appear for +error.svelte files?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not without having multiple files per route (./$types.d.ts, ./$error-types.d.ts, ./$layout-types.d.ts), but we already decided against that when we created PageProps alongside LayoutProps

);
}

Expand Down Expand Up @@ -263,15 +265,8 @@ function update_types(config, routes, route, root, to_delete = new Set()) {

if (route.leaf.server) {
exports.push(
'export type Action<OutputData extends Record<string, any> | void = Record<string, any> | void> = Kit.Action<RouteParams, OutputData, RouteId>'
);
exports.push(
'export type Actions<OutputData extends Record<string, any> | void = Record<string, any> | void> = Kit.Actions<RouteParams, OutputData, RouteId>'
);
}

if (route.leaf.server) {
exports.push(
'export type Action<OutputData extends Record<string, any> | void = Record<string, any> | void> = Kit.Action<RouteParams, OutputData, RouteId>',
'export type Actions<OutputData extends Record<string, any> | void = Record<string, any> | void> = Kit.Actions<RouteParams, OutputData, RouteId>',
'export type PageProps = { params: RouteParams; data: PageData; form: ActionData }'
);
} else {
Expand Down
Loading