Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

add types for stores #1601

Merged
merged 8 commits into from
Oct 26, 2020
Merged
Changes from 1 commit
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
19 changes: 10 additions & 9 deletions runtime/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
declare module '@sapper/app' {
import { Readable, Writable } from 'svelte/store';
import { PageContext } from '@sapper/app/types';

export interface Redirect {
statusCode: number
location: string
Expand All @@ -8,7 +11,11 @@ declare module '@sapper/app' {
export function prefetch(href: string): Promise<{ redirect?: Redirect; data?: unknown }>;
export function prefetchRoutes(pathnames: string[]): Promise<void>;
export function start(opts: { target: Node }): Promise<void>;
export const stores: () => unknown;
export function stores(): {
preloading: Readable<boolean>
page: Readable<PageContext>
session: Writable<any>
};
}

declare module '@sapper/server' {
Expand Down Expand Up @@ -39,15 +46,9 @@ declare module '@sapper/common' {
redirect: (statusCode: number, location: string) => void;
}

export interface Page {
host: string;
path: string;
params: Record<string, string>;
query: Record<string, string | string[]>;
error?: Error;
}
export { PageContext as Page } from '@sapper/app/types';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also imported PageContext from @sapper/app/types as to not re-declare it.


export interface Preload {
(this: PreloadContext, page: Page, session: any): object | Promise<object>;
(this: PreloadContext, page: PageContext, session: any): object | Promise<object>;
}

Choose a reason for hiding this comment

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

	export interface Preload<Props = object, Session = any> {
		(this: PreloadContext, page: PageContext, session: Session): Props | Promise<Props>;
	}

}