Skip to content

Improve types for the load wrapper #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions src/lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ export const flashCookieOptions: CookieSerializeOptions = {
/**
* @deprecated Renamed to loadFlash.
*/
export function loadFlashMessage<S extends ServerLoad, E extends ServerLoadEvent>(cb: S) {
return loadFlash<S, E>(cb);
export function loadFlashMessage<E extends ServerLoadEvent, R>(load: (event: E) => R) {
return loadFlash(load);
}

/**
* Retrieves the flash message from the previous request.
* Use as a wrapper around a top-level load function, usually in a +layout.server.ts file.
*/
export function loadFlash<S extends ServerLoad, E extends ServerLoadEvent>(cb: S) {
export function loadFlash<E extends ServerLoadEvent, R>(load: (event: E) => R) {
return async (event: E) => {
const flash = _loadFlash(event).flash;
const loadFunction = await cb(event);
return { flash, ...loadFunction } as ReturnType<S>;
const loadReturn = await load(event);
return { flash, ...loadReturn } as typeof loadReturn;
};
}

Expand Down