-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
Even more type improvements #146
Conversation
@@ -62,9 +58,9 @@ export interface ServerAdapterObject< | |||
): Promise<Response> | Response; | |||
} | |||
|
|||
export type ServerAdapter<TServerContext, TBaseObject extends ServerAdapterBaseObject<TServerContext>> = TBaseObject & |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we still able to keep other methods of given object in the returned object?
const app = createServerAdapter(Router());
app.get('/', req => ...);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, so that is the reason why we need the TBaseObject generic.
The thing is, with the current setup (on master
), inference does not work with the context. Try this:
interface Ctx {
some: string;
}
const handler = (_req: Request, _ctx: Ctx) => new Response();
const adapter = createServerAdapter(handler); // TS error with handler
const request = new Request('http://localhost');
await adapter(request, ctx); // TS error with request
even passing in the Ctx
as generic creates problems:
- const adapter = createServerAdapter(handler);
+ const adapter = createServerAdapter<Ctx>(handler);
ServerAdapter
implementsrequestListener
tooNodeServerAdapterContext
(previouslyDefaultServerAdapterContext
) is not the default context - it is the context only when using Node request handler. Shouldn't be used as default for context generic.