Skip to content

Commit c87236a

Browse files
committed
[chore] prefer interfaces to types
1 parent d0f2afd commit c87236a

File tree

6 files changed

+65
-65
lines changed

6 files changed

+65
-65
lines changed

packages/kit/test/types.d.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { RequestInfo, RequestInit, Response as NodeFetchResponse } from 'node-fe
77
// seems like that's no longer an issue? in which case we don't need
88
// to wrap all these methods
99

10-
export type TestContext = {
10+
export interface TestContext {
1111
base: string;
1212
page: Page;
1313
pages: {
@@ -34,14 +34,14 @@ export type TestContext = {
3434
server: import('net').Server;
3535
reset: () => Promise<void>;
3636
unpatch: () => void;
37-
};
37+
}
3838

39-
type TestOptions = {
39+
interface TestOptions {
4040
js?: boolean;
4141
nojs?: boolean;
4242
dev?: boolean;
4343
build?: boolean;
44-
};
44+
}
4545

4646
export interface TestFunctionBase {
4747
(

packages/kit/types/config.d.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Logger, TrailingSlash } from './internal';
22
import { UserConfig as ViteConfig } from 'vite';
33

4-
export type AdapterUtils = {
4+
export interface AdapterUtils {
55
log: Logger;
66
rimraf: (dir: string) => void;
77
mkdirp: (dir: string) => void;
@@ -18,14 +18,14 @@ export type AdapterUtils = {
1818
dest: string;
1919
fallback?: string;
2020
}) => Promise<void>;
21-
};
21+
}
2222

23-
export type Adapter = {
23+
export interface Adapter {
2424
name: string;
2525
adapt: ({ utils, config }: { utils: AdapterUtils; config: ValidatedConfig }) => Promise<void>;
26-
};
26+
}
2727

28-
export type Config = {
28+
export interface Config {
2929
compilerOptions?: any;
3030
extensions?: string[];
3131
kit?: {
@@ -76,9 +76,9 @@ export type Config = {
7676
vite?: ViteConfig | (() => ViteConfig);
7777
};
7878
preprocess?: any;
79-
};
79+
}
8080

81-
export type ValidatedConfig = {
81+
export interface ValidatedConfig {
8282
compilerOptions: any;
8383
extensions: string[];
8484
kit: {
@@ -130,4 +130,4 @@ export type ValidatedConfig = {
130130
vite: () => ViteConfig;
131131
};
132132
preprocess: any;
133-
};
133+
}

packages/kit/types/endpoint.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ type JSONValue =
1212

1313
type DefaultBody = JSONValue | Uint8Array;
1414

15-
export type EndpointOutput<Body extends DefaultBody = DefaultBody> = {
15+
export interface EndpointOutput<Body extends DefaultBody = DefaultBody> {
1616
status?: number;
1717
headers?: Headers;
1818
body?: Body;
19-
};
19+
}
2020

2121
export type RequestHandler<
2222
Locals = Record<string, any>,

packages/kit/types/hooks.d.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@ import { Headers, Location, MaybePromise, ParameterizedBody } from './helper';
22

33
export type StrictBody = string | Uint8Array;
44

5-
export type ServerRequest<Locals = Record<string, any>, Body = unknown> = Location & {
5+
export interface ServerRequest<Locals = Record<string, any>, Body = unknown> extends Location {
66
method: string;
77
headers: Headers;
88
rawBody: StrictBody;
99
body: ParameterizedBody<Body>;
1010
locals: Locals;
11-
};
11+
}
1212

13-
export type ServerResponse = {
13+
export interface ServerResponse {
1414
status: number;
1515
headers: Headers;
1616
body?: StrictBody;
17-
};
17+
}
1818

19-
export type GetSession<Locals = Record<string, any>, Session = any> = {
19+
export interface GetSession<Locals = Record<string, any>, Session = any> {
2020
(request: ServerRequest<Locals>): MaybePromise<Session>;
21-
};
21+
}
2222

2323
export type Handle<Locals = Record<string, any>> = (input: {
2424
request: ServerRequest<Locals>;

packages/kit/types/internal.d.ts

+36-36
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@ import { Load } from './page';
55

66
type PageId = string;
77

8-
export type Incoming = Omit<Location, 'params'> & {
8+
export interface Incoming extends Omit<Location, 'params'> {
99
method: string;
1010
headers: Headers;
1111
rawBody: StrictBody;
1212
body?: ParameterizedBody;
13-
};
13+
}
1414

15-
export type Logger = {
15+
export interface Logger {
1616
(msg: string): void;
1717
success: (msg: string) => void;
1818
error: (msg: string) => void;
1919
warn: (msg: string) => void;
2020
minor: (msg: string) => void;
2121
info: (msg: string) => void;
22-
};
22+
}
2323

24-
export type App = {
24+
export interface App {
2525
init: ({
2626
paths,
2727
prerendering,
@@ -44,9 +44,9 @@ export type App = {
4444
};
4545
}
4646
) => Promise<ServerResponse>;
47-
};
47+
}
4848

49-
export type SSRComponent = {
49+
export interface SSRComponent {
5050
ssr?: boolean;
5151
router?: boolean;
5252
hydrate?: boolean;
@@ -65,22 +65,22 @@ export type SSRComponent = {
6565
};
6666
};
6767
};
68-
};
68+
}
6969

7070
export type SSRComponentLoader = () => Promise<SSRComponent>;
7171

7272
export type CSRComponent = any; // TODO
7373

7474
export type CSRComponentLoader = () => Promise<CSRComponent>;
7575

76-
export type SSRPagePart = {
76+
export interface SSRPagePart {
7777
id: string;
7878
load: SSRComponentLoader;
79-
};
79+
}
8080

8181
export type GetParams = (match: RegExpExecArray) => Record<string, string>;
8282

83-
export type SSRPage = {
83+
export interface SSRPage {
8484
type: 'page';
8585
pattern: RegExp;
8686
params: GetParams;
@@ -90,16 +90,16 @@ export type SSRPage = {
9090
// plan b — and render that instead
9191
a: PageId[];
9292
b: PageId[];
93-
};
93+
}
9494

95-
export type SSREndpoint = {
95+
export interface SSREndpoint {
9696
type: 'endpoint';
9797
pattern: RegExp;
9898
params: GetParams;
9999
load: () => Promise<{
100100
[method: string]: RequestHandler;
101101
}>;
102-
};
102+
}
103103

104104
export type SSRRoute = SSREndpoint | SSRPage;
105105

@@ -109,28 +109,28 @@ export type CSREndpoint = [RegExp];
109109

110110
export type CSRRoute = CSREndpoint | CSRPage;
111111

112-
export type SSRManifest = {
112+
export interface SSRManifest {
113113
assets: Asset[];
114114
layout: string;
115115
error: string;
116116
routes: SSRRoute[];
117-
};
117+
}
118118

119-
export type Hooks = {
119+
export interface Hooks {
120120
getSession: GetSession;
121121
handle: Handle;
122122
serverFetch: ServerFetch;
123-
};
123+
}
124124

125-
export type SSRNode = {
125+
export interface SSRNode {
126126
module: SSRComponent;
127127
entry: string; // client-side module corresponding to this component
128128
css: string[];
129129
js: string[];
130130
styles: string[];
131-
};
131+
}
132132

133-
export type SSRRenderOptions = {
133+
export interface SSRRenderOptions {
134134
amp: boolean;
135135
dev: boolean;
136136
entry: {
@@ -157,9 +157,9 @@ export type SSRRenderOptions = {
157157
target: string;
158158
template: ({ head, body }: { head: string; body: string }) => string;
159159
trailing_slash: TrailingSlash;
160-
};
160+
}
161161

162-
export type SSRRenderState = {
162+
export interface SSRRenderState {
163163
fetched?: string;
164164
initiator?: SSRPage | null;
165165
prerender?: {
@@ -169,54 +169,54 @@ export type SSRRenderState = {
169169
error: Error;
170170
};
171171
fallback?: string;
172-
};
172+
}
173173

174-
export type Asset = {
174+
export interface Asset {
175175
file: string;
176176
size: number;
177177
type: string | null;
178-
};
178+
}
179179

180-
export type PageData = {
180+
export interface PageData {
181181
type: 'page';
182182
pattern: RegExp;
183183
params: string[];
184184
path: string;
185185
a: string[];
186186
b: string[];
187-
};
187+
}
188188

189-
export type EndpointData = {
189+
export interface EndpointData {
190190
type: 'endpoint';
191191
pattern: RegExp;
192192
params: string[];
193193
file: string;
194-
};
194+
}
195195

196196
export type RouteData = PageData | EndpointData;
197197

198-
export type ManifestData = {
198+
export interface ManifestData {
199199
assets: Asset[];
200200
layout: string;
201201
error: string;
202202
components: string[];
203203
routes: RouteData[];
204-
};
204+
}
205205

206-
export type BuildData = {
206+
export interface BuildData {
207207
client: string[];
208208
server: string[];
209209
static: string[];
210210
entries: string[];
211-
};
211+
}
212212

213-
export type NormalizedLoadOutput = {
213+
export interface NormalizedLoadOutput {
214214
status: number;
215215
error?: Error;
216216
redirect?: string;
217217
props?: Record<string, any> | Promise<Record<string, any>>;
218218
context?: Record<string, any>;
219219
maxage?: number;
220-
};
220+
}
221221

222222
export type TrailingSlash = 'never' | 'always' | 'ignore';

packages/kit/types/page.d.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
import { Location as Page, MaybePromise, InferValue } from './helper';
22

3-
export type LoadInput<
3+
export interface LoadInput<
44
PageParams extends Record<string, string> = Record<string, string>,
55
Context extends Record<string, any> = Record<string, any>,
66
Session = any
7-
> = {
7+
> {
88
page: Page<PageParams>;
99
fetch: (info: RequestInfo, init?: RequestInit) => Promise<Response>;
1010
session: Session;
1111
context: Context;
12-
};
12+
}
1313

14-
export type ErrorLoadInput<
14+
export interface ErrorLoadInput<
1515
PageParams extends Record<string, string> = Record<string, string>,
1616
Context extends Record<string, any> = Record<string, any>,
1717
Session = any
18-
> = LoadInput<PageParams, Context, Session> & {
18+
> extends LoadInput<PageParams, Context, Session> {
1919
status?: number;
2020
error?: Error;
21-
};
21+
}
2222

23-
export type LoadOutput<
23+
export interface LoadOutput<
2424
Props extends Record<string, any> = Record<string, any>,
2525
Context extends Record<string, any> = Record<string, any>
26-
> = {
26+
> {
2727
status?: number;
2828
error?: string | Error;
2929
redirect?: string;
3030
props?: Props;
3131
context?: Context;
3232
maxage?: number;
33-
};
33+
}
3434

3535
// Publicized Types
3636
export type Load<

0 commit comments

Comments
 (0)