Better typing for `renderPage`?
See original GitHub issueFirst of all, thank you for this awesome lib (and really useful documentation)!
I was playing around with createPageRenderer
(I’m using Typescript + Vercel + SolidJS) like so:
const renderPage = createPageRenderer(...);
...
const pageContext = await renderPage(pageContextInit);
Here, my pageContext
should have custom fields that could be returned (like redirectTo
as in your examples, or cookies
, that is responsible to set Cookies on headers).
So I checked the renderPage
typings:
Good, there is a PageContextAdded
type that I can use:
const pageContext = await renderPage<MyCustomType, typeof pageContextInit>(pageContextInit);
This should have been enough I guess, but the right typing is not quite right IMO:
PageContextInit & (({ httpResponse: HttpResponse } & PageContextAdded) | { httpResponse: null })
Looking closer, PageContextAdded
is added to the return type only if httpResponse
is of type HttpResponse
, which in both of my use cases (redirect and cookies) is not necessarily the case.
Perhaps I’m doing this wrong? But if not, here is the typing I propose:
PageContextInit & { httpResponse: HttpResponse | null } & PageContextAdded
// or with Partial but it could mess some type definitions
PageContextInit & { httpResponse: HttpResponse | null } & Partial<PageContextAdded>
// see https://www.typescriptlang.org/play?#code/C4TwDgpgBACghgcwgYQPYDtgQB7AIIAmBEBUAvFAN4BQUUcAXFOgK4C2ARhAE4A0tUDk1ace-AL5QAPlSgBjYey7co4gNzVqoSFAAa5WHG7AAlnAA2AHnhI0mHPiIkAfBupyMAZ2BRsTfRSU9EwAjLyCTABMqhoe6N5QIEw2KBhYuITEpIHBUGERUNHqmiYAZlAAFNgAdHAAlFQCdAD0zVAAogBKnQDynU3yXj5CzEo8BjUcGuIl5RUgtQ00dC1tAHKoUDzcqCpwnlvYkHJYBANxCSMiygYLU9TiQA
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (10 by maintainers)
Top GitHub Comments
Released in
v0.3.20
.The best would be https://github.com/brillout/vite-plugin-ssr/issues/176 so that all types are automatically stiched together for the user.