Skip to content

Commit 600c115

Browse files
AirBorne04ryansolidatilafassina
authored
Move RequestEventLocals type definition into a namespace to make the retyping easier for users (#1469)
* refactor RequestEventLocals into its own namespace for user retyping * adding change set * add placeholder for generic key value to RequestEventLocals * adding example declaration to the todommvc example * Update changeset to minor --------- Co-authored-by: Ryan Carniato <ryansolid@gmail.com> Co-authored-by: Atila Fassina <atila@fassina.eu>
1 parent 6b65ab2 commit 600c115

5 files changed

Lines changed: 22 additions & 15 deletions

File tree

.changeset/twenty-singers-fetch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/start": minor
3+
---
4+
5+
move the RequestEventLocals definition into the App namespace for easier end user retyping

examples/todomvc/src/global.d.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
/// <reference types="@solidjs/start/env" />
1+
declare module App {
2+
interface RequestEventLocals {
3+
/**
4+
* Declare your getRequestEvent().locals here
5+
*/
6+
}
7+
}

packages/start/env.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
/* eslint-disable @typescript-eslint/consistent-type-imports */
66

7+
declare namespace App {
8+
export interface RequestEventLocals {
9+
[key: string | symbol]: any;
10+
}
11+
}
12+
713
interface ImportMetaEnv extends Record<`VITE_${string}`, any>, SolidStartMetaEnv {
814
BASE_URL: string;
915
MODE: string;

packages/start/src/server/index.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,7 @@ export { StartServer } from "./StartServer";
33
export { createHandler } from "./handler";
44
export { getServerFunctionMeta } from "./serverFunction";
55
export type {
6-
DocumentComponentProps,
7-
Asset,
8-
HandlerOptions,
9-
ContextMatches,
10-
ResponseStub,
11-
FetchEvent,
12-
RequestEventLocals,
13-
PageEvent,
146
APIEvent,
15-
APIHandler,
16-
ServerFunctionMeta
7+
APIHandler, Asset, ContextMatches, DocumentComponentProps, FetchEvent, HandlerOptions, PageEvent, ResponseStub, ServerFunctionMeta
178
} from "./types";
189

packages/start/src/server/types.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,15 @@ export interface ResponseStub {
4242
statusText?: string;
4343
headers: Headers;
4444
}
45+
4546
export interface FetchEvent {
4647
request: Request;
4748
response: ResponseStub;
4849
clientAddress?: string;
49-
locals: RequestEventLocals;
50+
locals: App.RequestEventLocals;
5051
nativeEvent: HTTPEvent;
5152
}
52-
export interface RequestEventLocals {
53-
[key: string | symbol]: any;
54-
}
53+
5554
export interface PageEvent extends RequestEvent {
5655
manifest: any;
5756
assets: any;

0 commit comments

Comments
 (0)