title |
---|
TypeScript |
All APIs in SvelteKit are fully typed. Additionally, it's possible to tell SvelteKit how to type objects inside your app by declaring the App
namespace. By default, a new project will have a file called src/app.d.ts
containing the following:
/// <reference types="@sveltejs/kit" />
declare namespace App {
interface Locals {}
interface Platform {}
interface Session {}
interface Stuff {}
}
By populating these interfaces, you will gain type safety when using event.locals
, event.platform
, session
and stuff
:
The interface that defines event.locals
, which can be accessed in hooks (handle
, handleError
and getSession
) and endpoints.
If your adapter provides platform-specific context via event.platform
, you can specify it here.
The interface that defines session
, both as an argument to load
functions and the value of the session store.
The interface that defines stuff
, as input or output to load
or as the value of the stuff
property of the page store.