From 1bed8867898f03686737ed207eb7a437f3f8d4d0 Mon Sep 17 00:00:00 2001 From: JeanJPNM <61994401+JeanJPNM@users.noreply.github.com> Date: Wed, 11 Aug 2021 00:13:05 -0300 Subject: [PATCH] [chore] type functions as methods for semantics (#2158) --- .changeset/cuddly-pens-buy.md | 5 ++++ packages/kit/src/core/config/types.d.ts | 2 +- packages/kit/test/types.d.ts | 22 +++++++-------- packages/kit/types/config.d.ts | 16 +++++------ packages/kit/types/helper.d.ts | 14 +++++----- packages/kit/types/hooks.d.ts | 2 +- packages/kit/types/internal.d.ts | 36 ++++++++++++------------- packages/kit/types/page.d.ts | 2 +- 8 files changed, 52 insertions(+), 47 deletions(-) create mode 100644 .changeset/cuddly-pens-buy.md diff --git a/.changeset/cuddly-pens-buy.md b/.changeset/cuddly-pens-buy.md new file mode 100644 index 000000000000..97504c70ae4e --- /dev/null +++ b/.changeset/cuddly-pens-buy.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +Replace function properties by methods on type declarations diff --git a/packages/kit/src/core/config/types.d.ts b/packages/kit/src/core/config/types.d.ts index b1aa02f96890..530444101833 100644 --- a/packages/kit/src/core/config/types.d.ts +++ b/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'; diff --git a/packages/kit/test/types.d.ts b/packages/kit/test/types.d.ts index 87b55c774b2d..f8c6c9fec627 100644 --- a/packages/kit/test/types.d.ts +++ b/packages/kit/test/types.d.ts @@ -15,25 +15,25 @@ export interface TestContext { nojs: Page; }; response: PlaywrightResponse; - clicknav: (selector: string) => Promise; - back: () => Promise; - fetch: (url: RequestInfo, opts?: RequestInit) => Promise; - capture_requests: (fn: () => Promise) => Promise; - errors: () => string; + clicknav(selector: string): Promise; + back(): Promise; + fetch(url: RequestInfo, opts?: RequestInit): Promise; + capture_requests(fn: () => Promise): Promise; + errors(): string; js: boolean; // these are assumed to have been put in the global scope by the layout app: { - goto: (url: string) => Promise; - invalidate: (url: string) => Promise; - prefetch: (url: string) => Promise; - prefetchRoutes: (urls?: string[]) => Promise; + goto(url: string): Promise; + invalidate(url: string): Promise; + prefetch(url: string): Promise; + prefetchRoutes(urls?: string[]): Promise; }; watcher: any; // watcher type is not exposed server: import('net').Server; - reset: () => Promise; - unpatch: () => void; + reset(): Promise; + unpatch(): void; } interface TestOptions { diff --git a/packages/kit/types/config.d.ts b/packages/kit/types/config.d.ts index a7d34c05c54f..e004ff0cb08c 100644 --- a/packages/kit/types/config.d.ts +++ b/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; + 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; } export interface Adapter { name: string; - adapt: (context: { utils: AdapterUtils; config: ValidatedConfig }) => Promise; + adapt(context: { utils: AdapterUtils; config: ValidatedConfig }): Promise; } export interface PrerenderErrorHandler { diff --git a/packages/kit/types/helper.d.ts b/packages/kit/types/helper.d.ts index ffc2d3dfd4cf..fe6d8264def4 100644 --- a/packages/kit/types/helper.d.ts +++ b/packages/kit/types/helper.d.ts @@ -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; - values: () => Generator; - [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; + values(): Generator; + [Symbol.iterator](): Generator<[string, string], void>; } type BaseBody = string | Uint8Array | ReadOnlyFormData; diff --git a/packages/kit/types/hooks.d.ts b/packages/kit/types/hooks.d.ts index 48461d9105f9..a4ddc095125b 100644 --- a/packages/kit/types/hooks.d.ts +++ b/packages/kit/types/hooks.d.ts @@ -23,7 +23,7 @@ export interface GetSession, Session = any> { export interface Handle> { (input: { request: ServerRequest; - resolve: (request: ServerRequest) => MaybePromise; + resolve(request: ServerRequest): MaybePromise; }): MaybePromise; } diff --git a/packages/kit/types/internal.d.ts b/packages/kit/types/internal.d.ts index 15840ae28d30..bd39f2f5b3ac 100644 --- a/packages/kit/types/internal.d.ts +++ b/packages/kit/types/internal.d.ts @@ -14,15 +14,15 @@ export interface Incoming extends Omit { 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; }; } - ) => Promise; + ): Promise; } export interface SSRComponent { @@ -54,9 +54,9 @@ export interface SSRComponent { preload?: any; // TODO remove for 1.0 load: Load; default: { - render: ( + render( props: Record - ) => { + ): { 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; + load_component(id: PageId): Promise; 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; } diff --git a/packages/kit/types/page.d.ts b/packages/kit/types/page.d.ts index e06507ac4c03..7f695380be69 100644 --- a/packages/kit/types/page.d.ts +++ b/packages/kit/types/page.d.ts @@ -6,7 +6,7 @@ export interface LoadInput< Session = any > { page: Page; - fetch: (info: RequestInfo, init?: RequestInit) => Promise; + fetch(info: RequestInfo, init?: RequestInit): Promise; session: Session; context: Context; }