Skip to content

Commit 1bed886

Browse files
authored
[chore] type functions as methods for semantics (#2158)
1 parent 0f9f017 commit 1bed886

File tree

8 files changed

+52
-47
lines changed

8 files changed

+52
-47
lines changed

.changeset/cuddly-pens-buy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
Replace function properties by methods on type declarations

packages/kit/src/core/config/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export type ConfigDefinition =
22
| {
33
type: 'leaf';
44
default: any;
5-
validate: (value: any, keypath: string) => any;
5+
validate(value: any, keypath: string): any;
66
}
77
| {
88
type: 'branch';

packages/kit/test/types.d.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@ export interface TestContext {
1515
nojs: Page;
1616
};
1717
response: PlaywrightResponse;
18-
clicknav: (selector: string) => Promise<void>;
19-
back: () => Promise<void>;
20-
fetch: (url: RequestInfo, opts?: RequestInit) => Promise<NodeFetchResponse>;
21-
capture_requests: (fn: () => Promise<void>) => Promise<string[]>;
22-
errors: () => string;
18+
clicknav(selector: string): Promise<void>;
19+
back(): Promise<void>;
20+
fetch(url: RequestInfo, opts?: RequestInit): Promise<NodeFetchResponse>;
21+
capture_requests(fn: () => Promise<void>): Promise<string[]>;
22+
errors(): string;
2323
js: boolean;
2424

2525
// these are assumed to have been put in the global scope by the layout
2626
app: {
27-
goto: (url: string) => Promise<void>;
28-
invalidate: (url: string) => Promise<void>;
29-
prefetch: (url: string) => Promise<void>;
30-
prefetchRoutes: (urls?: string[]) => Promise<void>;
27+
goto(url: string): Promise<void>;
28+
invalidate(url: string): Promise<void>;
29+
prefetch(url: string): Promise<void>;
30+
prefetchRoutes(urls?: string[]): Promise<void>;
3131
};
3232

3333
watcher: any; // watcher type is not exposed
3434
server: import('net').Server;
35-
reset: () => Promise<void>;
36-
unpatch: () => void;
35+
reset(): Promise<void>;
36+
unpatch(): void;
3737
}
3838

3939
interface TestOptions {

packages/kit/types/config.d.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ import { Logger, TrailingSlash } from './internal';
44

55
export interface AdapterUtils {
66
log: Logger;
7-
rimraf: (dir: string) => void;
8-
mkdirp: (dir: string) => void;
9-
copy_client_files: (dest: string) => void;
10-
copy_server_files: (dest: string) => void;
11-
copy_static_files: (dest: string) => void;
12-
copy: (from: string, to: string, filter?: (basename: string) => boolean) => void;
13-
prerender: (options: { all?: boolean; dest: string; fallback?: string }) => Promise<void>;
7+
rimraf(dir: string): void;
8+
mkdirp(dir: string): void;
9+
copy_client_files(dest: string): void;
10+
copy_server_files(dest: string): void;
11+
copy_static_files(dest: string): void;
12+
copy(from: string, to: string, filter?: (basename: string) => boolean): void;
13+
prerender(options: { all?: boolean; dest: string; fallback?: string }): Promise<void>;
1414
}
1515

1616
export interface Adapter {
1717
name: string;
18-
adapt: (context: { utils: AdapterUtils; config: ValidatedConfig }) => Promise<void>;
18+
adapt(context: { utils: AdapterUtils; config: ValidatedConfig }): Promise<void>;
1919
}
2020

2121
export interface PrerenderErrorHandler {

packages/kit/types/helper.d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
interface ReadOnlyFormData {
2-
get: (key: string) => string;
3-
getAll: (key: string) => string[];
4-
has: (key: string) => boolean;
5-
entries: () => Generator<[string, string], void>;
6-
keys: () => Generator<string, void>;
7-
values: () => Generator<string, void>;
8-
[Symbol.iterator]: () => Generator<[string, string], void>;
2+
get(key: string): string;
3+
getAll(key: string): string[];
4+
has(key: string): boolean;
5+
entries(): Generator<[string, string], void>;
6+
keys(): Generator<string, void>;
7+
values(): Generator<string, void>;
8+
[Symbol.iterator](): Generator<[string, string], void>;
99
}
1010

1111
type BaseBody = string | Uint8Array | ReadOnlyFormData;

packages/kit/types/hooks.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface GetSession<Locals = Record<string, any>, Session = any> {
2323
export interface Handle<Locals = Record<string, any>> {
2424
(input: {
2525
request: ServerRequest<Locals>;
26-
resolve: (request: ServerRequest<Locals>) => MaybePromise<ServerResponse>;
26+
resolve(request: ServerRequest<Locals>): MaybePromise<ServerResponse>;
2727
}): MaybePromise<ServerResponse>;
2828
}
2929

packages/kit/types/internal.d.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ export interface Incoming extends Omit<Location, 'params'> {
1414

1515
export interface Logger {
1616
(msg: string): void;
17-
success: (msg: string) => void;
18-
error: (msg: string) => void;
19-
warn: (msg: string) => void;
20-
minor: (msg: string) => void;
21-
info: (msg: string) => void;
17+
success(msg: string): void;
18+
error(msg: string): void;
19+
warn(msg: string): void;
20+
minor(msg: string): void;
21+
info(msg: string): void;
2222
}
2323

2424
export interface App {
25-
init: ({
25+
init({
2626
paths,
2727
prerendering,
2828
read
@@ -32,9 +32,9 @@ export interface App {
3232
assets: string;
3333
};
3434
prerendering: boolean;
35-
read: (file: string) => Buffer;
36-
}) => void;
37-
render: (
35+
read(file: string): Buffer;
36+
}): void;
37+
render(
3838
incoming: Incoming,
3939
options?: {
4040
prerender: {
@@ -43,7 +43,7 @@ export interface App {
4343
dependencies?: Map<string, ServerResponse>;
4444
};
4545
}
46-
) => Promise<ServerResponse>;
46+
): Promise<ServerResponse>;
4747
}
4848

4949
export interface SSRComponent {
@@ -54,9 +54,9 @@ export interface SSRComponent {
5454
preload?: any; // TODO remove for 1.0
5555
load: Load;
5656
default: {
57-
render: (
57+
render(
5858
props: Record<string, any>
59-
) => {
59+
): {
6060
html: string;
6161
head: string;
6262
css: {
@@ -99,7 +99,7 @@ export interface SSREndpoint {
9999
type: 'endpoint';
100100
pattern: RegExp;
101101
params: GetParams;
102-
load: () => Promise<{
102+
load(): Promise<{
103103
[method: string]: RequestHandler;
104104
}>;
105105
}
@@ -142,24 +142,24 @@ export interface SSRRenderOptions {
142142
js: string[];
143143
};
144144
floc: boolean;
145-
get_stack: (error: Error) => string | undefined;
146-
handle_error: (error: Error) => void;
145+
get_stack(error: Error): string | undefined;
146+
handle_error(error: Error): void;
147147
hooks: Hooks;
148148
hydrate: boolean;
149-
load_component: (id: PageId) => Promise<SSRNode>;
149+
load_component(id: PageId): Promise<SSRNode>;
150150
manifest: SSRManifest;
151151
paths: {
152152
base: string;
153153
assets: string;
154154
};
155155
prerender: boolean;
156-
read: (file: string) => Buffer;
156+
read(file: string): Buffer;
157157
root: SSRComponent['default'];
158158
router: boolean;
159159
service_worker?: string;
160160
ssr: boolean;
161161
target: string;
162-
template: ({ head, body }: { head: string; body: string }) => string;
162+
template({ head, body }: { head: string; body: string }): string;
163163
trailing_slash: TrailingSlash;
164164
}
165165

packages/kit/types/page.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export interface LoadInput<
66
Session = any
77
> {
88
page: Page<PageParams>;
9-
fetch: (info: RequestInfo, init?: RequestInit) => Promise<Response>;
9+
fetch(info: RequestInfo, init?: RequestInit): Promise<Response>;
1010
session: Session;
1111
context: Context;
1212
}

0 commit comments

Comments
 (0)