From 31f4b884beb46d4eac57818e74fd4b8cb8c99f5a Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Fri, 25 Jul 2025 19:45:55 +0100 Subject: [PATCH] fix: specify return type in DTS declarations If we specify the return type in the JSDoc for `getRequestEvent`, the DTS emit corrects itself and no longer pulls in a missing symbol. Maybe this means we don't need the generate hack? --- packages/kit/scripts/generate-dts.js | 8 +------- packages/kit/src/runtime/app/server/event.js | 1 + packages/kit/types/index.d.ts | 6 ++---- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/packages/kit/scripts/generate-dts.js b/packages/kit/scripts/generate-dts.js index 1af5db6ae96b..e8579ec59054 100644 --- a/packages/kit/scripts/generate-dts.js +++ b/packages/kit/scripts/generate-dts.js @@ -1,5 +1,5 @@ import { createBundle } from 'dts-buddy'; -import { readFileSync, writeFileSync } from 'node:fs'; +import { readFileSync } from 'node:fs'; await createBundle({ output: 'types/index.d.ts', @@ -28,9 +28,3 @@ if (types.includes('__sveltekit/')) { types ); } - -// this is hacky as all hell but it gets the tests passing. might be a bug in dts-buddy? -// prettier-ignore -writeFileSync('./types/index.d.ts', types.replace("declare module '$app/server' {", `declare module '$app/server' { - // @ts-ignore - import { LayoutParams as AppLayoutParams, RouteId as AppRouteId } from '$app/types'`)); diff --git a/packages/kit/src/runtime/app/server/event.js b/packages/kit/src/runtime/app/server/event.js index 8351e21e9000..436d6010ac47 100644 --- a/packages/kit/src/runtime/app/server/event.js +++ b/packages/kit/src/runtime/app/server/event.js @@ -19,6 +19,7 @@ import('node:async_hooks') * * In environments without [`AsyncLocalStorage`](https://nodejs.org/api/async_context.html#class-asynclocalstorage), this must be called synchronously (i.e. not after an `await`). * @since 2.20.0 + * @returns {RequestEvent} */ export function getRequestEvent() { const event = request_event ?? als?.getStore(); diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index 68107c9040b4..c353b19754a5 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -2434,8 +2434,6 @@ declare module '$app/paths' { } declare module '$app/server' { - // @ts-ignore - import { LayoutParams as AppLayoutParams, RouteId as AppRouteId } from '$app/types' import type { RequestEvent } from '@sveltejs/kit'; /** * Read the contents of an imported asset from the filesystem @@ -2455,8 +2453,8 @@ declare module '$app/server' { * * In environments without [`AsyncLocalStorage`](https://nodejs.org/api/async_context.html#class-asynclocalstorage), this must be called synchronously (i.e. not after an `await`). * @since 2.20.0 - */ - export function getRequestEvent(): RequestEvent, any>; + * */ + export function getRequestEvent(): RequestEvent; export {}; }