[chore] type functions as methods for semantics
ADD
.changeset/cuddly-pens-buy.md
+---
+'@sveltejs/kit': patch
+---
+
+Replace function properties by methods on type declarations

MODIFY
packages/kit/src/core/config/types.d.ts
packages/kit/src/core/config/types.d.ts
@@ -2,7 +2,7 @@ export type ConfigDefinition =
| {
type: 'leaf';
default: any;
- validate: (value: any, keypath: string) => any;
+ validate(value: any, keypath: string): any;
}
| {
type: 'branch';

MODIFY
packages/kit/test/types.d.ts
packages/kit/test/types.d.ts
@@ -15,25 +15,25 @@ export interface TestContext {
nojs: Page;
};
response: PlaywrightResponse;
- clicknav: (selector: string) => Promise<void>;
- back: () => Promise<void>;
- fetch: (url: RequestInfo, opts?: RequestInit) => Promise<NodeFetchResponse>;
- capture_requests: (fn: () => Promise<void>) => Promise<string[]>;
- errors: () => string;
+ clicknav(selector: string): Promise<void>;
+ back(): Promise<void>;
+ fetch(url: RequestInfo, opts?: RequestInit): Promise<NodeFetchResponse>;
+ capture_requests(fn: () => Promise<void>): Promise<string[]>;
+ errors(): string;
js: boolean;
// these are assumed to have been put in the global scope by the layout
app: {
- goto: (url: string) => Promise<void>;
- invalidate: (url: string) => Promise<void>;
- prefetch: (url: string) => Promise<void>;
- prefetchRoutes: (urls?: string[]) => Promise<void>;
+ goto(url: string): Promise<void>;
+ invalidate(url: string): Promise<void>;
+ prefetch(url: string): Promise<void>;
+ prefetchRoutes(urls?: string[]): Promise<void>;
};
watcher: any; // watcher type is not exposed
server: import('net').Server;
- reset: () => Promise<void>;
- unpatch: () => void;
+ reset(): Promise<void>;
+ unpatch(): void;
}
interface TestOptions {

MODIFY
packages/kit/types/config.d.ts
packages/kit/types/config.d.ts
@@ -4,18 +4,18 @@ import { Logger, TrailingSlash } from './internal';
export interface AdapterUtils {
log: Logger;
- rimraf: (dir: string) => void;
- mkdirp: (dir: string) => void;
- copy_client_files: (dest: string) => void;
- copy_server_files: (dest: string) => void;
- copy_static_files: (dest: string) => void;
- copy: (from: string, to: string, filter?: (basename: string) => boolean) => void;
- prerender: (options: { all?: boolean; dest: string; fallback?: string }) => Promise<void>;
+ rimraf(dir: string): void;
+ mkdirp(dir: string): void;
+ copy_client_files(dest: string): void;
+ copy_server_files(dest: string): void;
+ copy_static_files(dest: string): void;
+ copy(from: string, to: string, filter?: (basename: string) => boolean): void;
+ prerender(options: { all?: boolean; dest: string; fallback?: string }): Promise<void>;
}
export interface Adapter {
name: string;
- adapt: (context: { utils: AdapterUtils; config: ValidatedConfig }) => Promise<void>;
+ adapt(context: { utils: AdapterUtils; config: ValidatedConfig }): Promise<void>;
}
export interface PrerenderErrorHandler {

MODIFY
packages/kit/types/helper.d.ts
packages/kit/types/helper.d.ts
interface ReadOnlyFormData {
- get: (key: string) => string;
- getAll: (key: string) => string[];
- has: (key: string) => boolean;
- entries: () => Generator<[string, string], void>;
- keys: () => Generator<string, void>;
- values: () => Generator<string, void>;
- [Symbol.iterator]: () => Generator<[string, string], void>;
+ get(key: string): string;
+ getAll(key: string): string[];
+ has(key: string): boolean;
+ entries(): Generator<[string, string], void>;
+ keys(): Generator<string, void>;
+ values(): Generator<string, void>;
+ [Symbol.iterator](): Generator<[string, string], void>;
}
type BaseBody = string | Uint8Array | ReadOnlyFormData;

MODIFY
packages/kit/types/hooks.d.ts
packages/kit/types/hooks.d.ts
@@ -23,7 +23,7 @@ export interface GetSession<Locals = Record<string, any>, Session = any> {
export interface Handle<Locals = Record<string, any>> {
(input: {
request: ServerRequest<Locals>;
- resolve: (request: ServerRequest<Locals>) => MaybePromise<ServerResponse>;
+ resolve(request: ServerRequest<Locals>): MaybePromise<ServerResponse>;
}): MaybePromise<ServerResponse>;
}

MODIFY
packages/kit/types/internal.d.ts
packages/kit/types/internal.d.ts
@@ -14,15 +14,15 @@ export interface Incoming extends Omit<Location, 'params'> {
export interface Logger {
(msg: string): void;
- success: (msg: string) => void;
- error: (msg: string) => void;
- warn: (msg: string) => void;
- minor: (msg: string) => void;
- info: (msg: string) => void;
+ success(msg: string): void;
+ error(msg: string): void;
+ warn(msg: string): void;
+ minor(msg: string): void;
+ info(msg: string): void;
}
export interface App {
- init: ({
+ init({
paths,
prerendering,
read
@@ -32,9 +32,9 @@ export interface App {
assets: string;
};
prerendering: boolean;
- read: (file: string) => Buffer;
- }) => void;
- render: (
+ read(file: string): Buffer;
+ }): void;
+ render(
incoming: Incoming,
options?: {
prerender: {
@@ -43,7 +43,7 @@ export interface App {
dependencies?: Map<string, ServerResponse>;
};
}
- ) => Promise<ServerResponse>;
+ ): Promise<ServerResponse>;
}
export interface SSRComponent {
@@ -54,9 +54,9 @@ export interface SSRComponent {
preload?: any; // TODO remove for 1.0
load: Load;
default: {
- render: (
+ render(
props: Record<string, any>
- ) => {
+ ): {
html: string;
head: string;
css: {
@@ -99,7 +99,7 @@ export interface SSREndpoint {
type: 'endpoint';
pattern: RegExp;
params: GetParams;
- load: () => Promise<{
+ load(): Promise<{
[method: string]: RequestHandler;
}>;
}
@@ -142,24 +142,24 @@ export interface SSRRenderOptions {
js: string[];
};
floc: boolean;
- get_stack: (error: Error) => string | undefined;
- handle_error: (error: Error) => void;
+ get_stack(error: Error): string | undefined;
+ handle_error(error: Error): void;
hooks: Hooks;
hydrate: boolean;
- load_component: (id: PageId) => Promise<SSRNode>;
+ load_component(id: PageId): Promise<SSRNode>;
manifest: SSRManifest;
paths: {
base: string;
assets: string;
};
prerender: boolean;
- read: (file: string) => Buffer;
+ read(file: string): Buffer;
root: SSRComponent['default'];
router: boolean;
service_worker?: string;
ssr: boolean;
target: string;
- template: ({ head, body }: { head: string; body: string }) => string;
+ template({ head, body }: { head: string; body: string }): string;
trailing_slash: TrailingSlash;
}

MODIFY
packages/kit/types/page.d.ts
packages/kit/types/page.d.ts
@@ -6,7 +6,7 @@ export interface LoadInput<
Session = any
> {
page: Page<PageParams>;
- fetch: (info: RequestInfo, init?: RequestInit) => Promise<Response>;
+ fetch(info: RequestInfo, init?: RequestInit): Promise<Response>;
session: Session;
context: Context;
}

[chore] type functions as methods for semantics (#2158)