Skip to content

Commit

Permalink
[chore] type functions as methods for semantics (#2158)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanJPNM authored Aug 11, 2021
1 parent 0f9f017 commit 1bed886
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 47 deletions.
5 changes: 5 additions & 0 deletions .changeset/cuddly-pens-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Replace function properties by methods on type declarations
2 changes: 1 addition & 1 deletion packages/kit/src/core/config/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
22 changes: 11 additions & 11 deletions packages/kit/test/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 8 additions & 8 deletions packages/kit/types/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions packages/kit/types/helper.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
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;
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/types/hooks.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
}

Expand Down
36 changes: 18 additions & 18 deletions packages/kit/types/internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: {
Expand All @@ -43,7 +43,7 @@ export interface App {
dependencies?: Map<string, ServerResponse>;
};
}
) => Promise<ServerResponse>;
): Promise<ServerResponse>;
}

export interface SSRComponent {
Expand All @@ -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: {
Expand Down Expand Up @@ -99,7 +99,7 @@ export interface SSREndpoint {
type: 'endpoint';
pattern: RegExp;
params: GetParams;
load: () => Promise<{
load(): Promise<{
[method: string]: RequestHandler;
}>;
}
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/kit/types/page.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 1bed886

Please sign in to comment.