Skip to content
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

fix: use arrow function types over bound functions #12955

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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/wet-dancers-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: use arrow function types over bound funcs
86 changes: 43 additions & 43 deletions packages/kit/src/exports/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface Adapter {
* This function is called after SvelteKit has built your app.
* @param builder An object provided by SvelteKit that contains methods for adapting the app
*/
adapt(builder: Builder): MaybePromise<void>;
adapt: (builder: Builder) => MaybePromise<void>;
/**
* Checks called during dev and build to determine whether specific features will work in production with this adapter
*/
Expand All @@ -49,7 +49,7 @@ export interface Adapter {
* Creates an `Emulator`, which allows the adapter to influence the environment
* during dev, build and prerendering
*/
emulate?(): MaybePromise<Emulator>;
emulate?: () => MaybePromise<Emulator>;
}

export type LoadProperties<input extends Record<string, any> | void> = input extends void
Expand Down Expand Up @@ -93,9 +93,9 @@ export interface Builder {
/** Print messages to the console. `log.info` and `log.minor` are silent unless Vite's `logLevel` is `info`. */
log: Logger;
/** Remove `dir` and all its contents. */
rimraf(dir: string): void;
rimraf: (dir: string) => void;
/** Create `dir` and any required parent directories. */
mkdirp(dir: string): void;
mkdirp: (dir: string) => void;

/** The fully resolved `svelte.config.js`. */
config: ValidatedConfig;
Expand All @@ -110,59 +110,59 @@ export interface Builder {
* @param fn A function that groups a set of routes into an entry point
* @deprecated Use `builder.routes` instead
*/
createEntries(fn: (route: RouteDefinition) => AdapterEntry): Promise<void>;
createEntries: (fn: (route: RouteDefinition) => AdapterEntry) => Promise<void>;

/**
* Find all the assets imported by server files belonging to `routes`
*/
findServerAssets(routes: RouteDefinition[]): string[];
findServerAssets: (routes: RouteDefinition[]) => string[];

/**
* Generate a fallback page for a static webserver to use when no route is matched. Useful for single-page apps.
*/
generateFallback(dest: string): Promise<void>;
generateFallback: (dest: string) => Promise<void>;

/**
* Generate a module exposing build-time environment variables as `$env/dynamic/public`.
*/
generateEnvModule(): void;
generateEnvModule: () => void;

/**
* Generate a server-side manifest to initialise the SvelteKit [server](https://svelte.dev/docs/kit/@sveltejs-kit#Server) with.
* @param opts a relative path to the base directory of the app and optionally in which format (esm or cjs) the manifest should be generated
*/
generateManifest(opts: { relativePath: string; routes?: RouteDefinition[] }): string;
generateManifest: (opts: { relativePath: string; routes?: RouteDefinition[] }) => string;

/**
* Resolve a path to the `name` directory inside `outDir`, e.g. `/path/to/.svelte-kit/my-adapter`.
* @param name path to the file, relative to the build directory
*/
getBuildDirectory(name: string): string;
getBuildDirectory: (name: string) => string;
/** Get the fully resolved path to the directory containing client-side assets, including the contents of your `static` directory. */
getClientDirectory(): string;
getClientDirectory: () => string;
/** Get the fully resolved path to the directory containing server-side code. */
getServerDirectory(): string;
getServerDirectory: () => string;
/** Get the application path including any configured `base` path, e.g. `my-base-path/_app`. */
getAppPath(): string;
getAppPath: () => string;

/**
* Write client assets to `dest`.
* @param dest the destination folder
* @returns an array of files written to `dest`
*/
writeClient(dest: string): string[];
writeClient: (dest: string) => string[];
/**
* Write prerendered files to `dest`.
* @param dest the destination folder
* @returns an array of files written to `dest`
*/
writePrerendered(dest: string): string[];
writePrerendered: (dest: string) => string[];
/**
* Write server-side code to `dest`.
* @param dest the destination folder
* @returns an array of files written to `dest`
*/
writeServer(dest: string): string[];
writeServer: (dest: string) => string[];
/**
* Copy a file or directory.
* @param from the source file or directory
Expand All @@ -171,20 +171,20 @@ export interface Builder {
* @param opts.replace a map of strings to replace
* @returns an array of files that were copied
*/
copy(
copy: (
from: string,
to: string,
opts?: {
filter?(basename: string): boolean;
replace?: Record<string, string>;
}
): string[];
) => string[];

/**
* Compress files in `directory` with gzip and brotli, where appropriate. Generates `.gz` and `.br` files alongside the originals.
* @param {string} directory The directory containing the files to be compressed
*/
compress(directory: string): Promise<void>;
compress: (directory: string) => Promise<void>;
}

export interface Config {
Expand Down Expand Up @@ -214,13 +214,13 @@ export interface Cookies {
* @param name the name of the cookie
* @param opts the options, passed directly to `cookie.parse`. See documentation [here](https://github.com/jshttp/cookie#cookieparsestr-options)
*/
get(name: string, opts?: import('cookie').CookieParseOptions): string | undefined;
get: (name: string, opts?: import('cookie').CookieParseOptions) => string | undefined;

/**
* Gets all cookies that were previously set with `cookies.set`, or from the request headers.
* @param opts the options, passed directly to `cookie.parse`. See documentation [here](https://github.com/jshttp/cookie#cookieparsestr-options)
*/
getAll(opts?: import('cookie').CookieParseOptions): Array<{ name: string; value: string }>;
getAll: (opts?: import('cookie').CookieParseOptions) => Array<{ name: string; value: string }>;

/**
* Sets a cookie. This will add a `set-cookie` header to the response, but also make the cookie available via `cookies.get` or `cookies.getAll` during the current request.
Expand All @@ -232,11 +232,11 @@ export interface Cookies {
* @param value the cookie value
* @param opts the options, passed directly to `cookie.serialize`. See documentation [here](https://github.com/jshttp/cookie#cookieserializename-value-options)
*/
set(
set: (
name: string,
value: string,
opts: import('cookie').CookieSerializeOptions & { path: string }
): void;
) => void;

/**
* Deletes a cookie by setting its value to an empty string and setting the expiry date in the past.
Expand All @@ -245,7 +245,7 @@ export interface Cookies {
* @param name the name of the cookie
* @param opts the options, passed directly to `cookie.serialize`. The `path` must match the path of the cookie you want to delete. See documentation [here](https://github.com/jshttp/cookie#cookieserializename-value-options)
*/
delete(name: string, opts: import('cookie').CookieSerializeOptions & { path: string }): void;
delete: (name: string, opts: import('cookie').CookieSerializeOptions & { path: string }) => void;

/**
* Serialize a cookie name-value pair into a `Set-Cookie` header string, but don't apply it to the response.
Expand All @@ -258,11 +258,11 @@ export interface Cookies {
* @param value the cookie value
* @param opts the options, passed directly to `cookie.serialize`. See documentation [here](https://github.com/jshttp/cookie#cookieserializename-value-options)
*/
serialize(
serialize: (
name: string,
value: string,
opts: import('cookie').CookieSerializeOptions & { path: string }
): string;
) => string;
}

/**
Expand Down Expand Up @@ -685,7 +685,7 @@ export interface KitConfig {
*/
export type Handle = (input: {
event: RequestEvent;
resolve(event: RequestEvent, opts?: ResolveOptions): MaybePromise<Response>;
resolve: (event: RequestEvent, opts?: ResolveOptions) => MaybePromise<Response>;
}) => MaybePromise<Response>;

/**
Expand Down Expand Up @@ -791,14 +791,14 @@ export interface LoadEvent<
*
* `setHeaders` has no effect when a `load` function runs in the browser.
*/
setHeaders(headers: Record<string, string>): void;
setHeaders: (headers: Record<string, string>) => void;
/**
* `await parent()` returns data from parent `+layout.js` `load` functions.
* Implicitly, a missing `+layout.js` is treated as a `({ data }) => data` function, meaning that it will return and forward data from parent `+layout.server.js` files.
*
* Be careful not to introduce accidental waterfalls when using `await parent()`. If for example you only want to merge parent data into the returned output, call it _after_ fetching your other data.
*/
parent(): Promise<ParentData>;
parent: () => Promise<ParentData>;
/**
* This function declares that the `load` function has a _dependency_ on one or more URLs or custom identifiers, which can subsequently be used with [`invalidate()`](https://svelte.dev/docs/kit/$app-navigation#invalidate) to cause `load` to rerun.
*
Expand Down Expand Up @@ -836,7 +836,7 @@ export interface LoadEvent<
* <button on:click={increase}>Increase Count</button>
* ```
*/
depends(...deps: Array<`${string}:${string}`>): void;
depends: (...deps: Array<`${string}:${string}`>) => void;
/**
* Use this function to opt out of dependency tracking for everything that is synchronously called within the callback. Example:
*
Expand All @@ -850,7 +850,7 @@ export interface LoadEvent<
* }
* ```
*/
untrack<T>(fn: () => T): T;
untrack: <T>(fn: () => T) => T;
}

export interface NavigationEvent<
Expand Down Expand Up @@ -945,7 +945,7 @@ export interface BeforeNavigate extends Navigation {
/**
* Call this to prevent the navigation from starting.
*/
cancel(): void;
cancel: () => void;
}

/**
Expand Down Expand Up @@ -1059,7 +1059,7 @@ export interface RequestEvent<
/**
* The client's IP address, set by the adapter.
*/
getClientAddress(): string;
getClientAddress: () => string;
/**
* Contains custom data that was added to the request within the [`server handle hook`](https://svelte.dev/docs/kit/hooks#Server-hooks-handle).
*/
Expand Down Expand Up @@ -1107,7 +1107,7 @@ export interface RequestEvent<
*
* You cannot add a `set-cookie` header with `setHeaders` — use the [`cookies`](https://svelte.dev/docs/kit/@sveltejs-kit#Cookies) API instead.
*/
setHeaders(headers: Record<string, string>): void;
setHeaders: (headers: Record<string, string>) => void;
/**
* The requested URL.
*/
Expand Down Expand Up @@ -1140,20 +1140,20 @@ export interface ResolveOptions {
* but they will always be split at sensible boundaries such as `%sveltekit.head%` or layout/page components.
* @param input the html chunk and the info if this is the last chunk
*/
transformPageChunk?(input: { html: string; done: boolean }): MaybePromise<string | undefined>;
transformPageChunk?: (input: { html: string; done: boolean }) => MaybePromise<string | undefined>;
/**
* Determines which headers should be included in serialized responses when a `load` function loads a resource with `fetch`.
* By default, none will be included.
* @param name header name
* @param value header value
*/
filterSerializedResponseHeaders?(name: string, value: string): boolean;
filterSerializedResponseHeaders?: (name: string, value: string) => boolean;
/**
* Determines what should be added to the `<head>` tag to preload it.
* By default, `js` and `css` files will be preloaded.
* @param input the type of the file and its path
*/
preload?(input: { type: 'font' | 'css' | 'js' | 'asset'; path: string }): boolean;
preload?: (input: { type: 'font' | 'css' | 'js' | 'asset'; path: string }) => boolean;
}

export interface RouteDefinition<Config = any> {
Expand Down Expand Up @@ -1195,7 +1195,7 @@ export interface SSRManifest {
client: NonNullable<BuildData['client']>;
nodes: SSRNodeLoader[];
routes: SSRRoute[];
matchers(): Promise<Record<string, ParamMatcher>>;
matchers: () => Promise<Record<string, ParamMatcher>>;
/** A `[file]: size` map of all assets imported by server code */
server_assets: Record<string, number>;
};
Expand All @@ -1222,7 +1222,7 @@ export interface ServerLoadEvent<
*
* Be careful not to introduce accidental waterfalls when using `await parent()`. If for example you only want to merge parent data into the returned output, call it _after_ fetching your other data.
*/
parent(): Promise<ParentData>;
parent: () => Promise<ParentData>;
/**
* This function declares that the `load` function has a _dependency_ on one or more URLs or custom identifiers, which can subsequently be used with [`invalidate()`](https://svelte.dev/docs/kit/$app-navigation#invalidate) to cause `load` to rerun.
*
Expand Down Expand Up @@ -1260,7 +1260,7 @@ export interface ServerLoadEvent<
* <button on:click={increase}>Increase Count</button>
* ```
*/
depends(...deps: string[]): void;
depends: (...deps: string[]) => void;
/**
* Use this function to opt out of dependency tracking for everything that is synchronously called within the callback. Example:
*
Expand All @@ -1274,7 +1274,7 @@ export interface ServerLoadEvent<
* }
* ```
*/
untrack<T>(fn: () => T): T;
untrack: <T>(fn: () => T) => T;
}

/**
Expand Down Expand Up @@ -1345,7 +1345,7 @@ export type SubmitFunction<
formElement: HTMLFormElement;
controller: AbortController;
submitter: HTMLElement | null;
cancel(): void;
cancel: () => void;
}) => MaybePromise<
| void
| ((opts: {
Expand All @@ -1358,7 +1358,7 @@ export type SubmitFunction<
* @param options Set `reset: false` if you don't want the `<form>` values to be reset after a successful submission.
* @param invalidateAll Set `invalidateAll: false` if you don't want the action to call `invalidateAll` after submission.
*/
update(options?: { reset?: boolean; invalidateAll?: boolean }): Promise<void>;
update: (options?: { reset?: boolean; invalidateAll?: boolean }) => Promise<void>;
}) => void)
>;

Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/runtime/server/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function get_cookies(request, url, trailing_slash) {

/**
* @param {string} name
* @param {import('cookie').CookieParseOptions} opts
* @param {import('cookie').CookieParseOptions} [opts]
*/
get(name, opts) {
const c = new_cookies[name];
Expand Down Expand Up @@ -89,7 +89,7 @@ export function get_cookies(request, url, trailing_slash) {
},

/**
* @param {import('cookie').CookieParseOptions} opts
* @param {import('cookie').CookieParseOptions} [opts]
*/
getAll(opts) {
const decoder = opts?.decode || decodeURIComponent;
Expand Down
Loading
Loading