Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move RequestEventLocals type definition into a namespace to make the retyping easier for users #1469

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
5 changes: 5 additions & 0 deletions .changeset/twenty-singers-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solidjs/start": minor
---

move the RequestEventLocals definition into the App namespace for easier end user retyping
8 changes: 7 additions & 1 deletion examples/todomvc/src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
/// <reference types="@solidjs/start/env" />
declare module App {
interface RequestEventLocals {
/**
* Declare your getRequestEvent().locals here
*/
}
}
6 changes: 6 additions & 0 deletions packages/start/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

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

declare namespace App {
export interface RequestEventLocals {
[key: string | symbol]: any;
}
}

interface ImportMetaEnv extends Record<`VITE_${string}`, any>, SolidStartMetaEnv {
BASE_URL: string;
MODE: string;
Expand Down
11 changes: 1 addition & 10 deletions packages/start/src/server/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,7 @@ export { StartServer } from "./StartServer";
export { createHandler } from "./handler";
export { getServerFunctionMeta } from "./serverFunction";
export type {
DocumentComponentProps,
Asset,
HandlerOptions,
ContextMatches,
ResponseStub,
FetchEvent,
RequestEventLocals,
PageEvent,
APIEvent,
APIHandler,
ServerFunctionMeta
APIHandler, Asset, ContextMatches, DocumentComponentProps, FetchEvent, HandlerOptions, PageEvent, ResponseStub, ServerFunctionMeta
} from "./types";

7 changes: 3 additions & 4 deletions packages/start/src/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,15 @@ export interface ResponseStub {
statusText?: string;
headers: Headers;
}

export interface FetchEvent {
request: Request;
response: ResponseStub;
clientAddress?: string;
locals: RequestEventLocals;
locals: App.RequestEventLocals;
nativeEvent: HTTPEvent;
}
export interface RequestEventLocals {
[key: string | symbol]: any;
}

export interface PageEvent extends RequestEvent {
manifest: any;
assets: any;
Expand Down