-
-
Notifications
You must be signed in to change notification settings - Fork 428
Conversation
runtime/index.d.ts
Outdated
query: Record<string, string | string[]>; | ||
error?: Error; | ||
} | ||
export { PageContext as Page } from '@sapper/app/types'; |
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.
Also imported PageContext from @sapper/app/types
as to not re-declare it.
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.
LGTM :)
|
server.ts is created like this:
so
|
I think PageContext has to be a type instead of an interface for this to work, please correct me if I am wrong. |
@TheComputerM Both type or interface should work. I just don't understand the "magic" behind |
So, shall I convert |
That file doesn't exist either? The only way I can get it to work, is to declare the namespace, directly in the index.d.ts
But now we're back to square one again :) |
This is the file |
Yes, but only in the source. I can't find it anywhere in If its not included in the sapper dist, or auto-generated [@]sapper, I dont see how we can import it. |
So how do we fix this? |
If |
One workaround would be to add
and remove it, when the import works? |
But im no expert here. I just want auto-complete to work :) |
Ok, If someone approves this, I will add this. |
And also,
|
To avoid compile error its should probably be or maybe better, change sapper-template to convert TS to
|
This is what we do, maybe it's better to ensure it exists instead of typecasting? const target = document.querySelector("#sapper");
if (target)
sapper.start({
target,
hydratable: true,
}); |
Found one more. In |
This is a useful discussion; the handling of types right now seems wrong. I looked into how the types work: in the
This is the reason why Therefore, those references from |
On the discussion around whether Furthermore, I don't think |
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.
Might be nice to parameterize these types to let users type the session and preloaded props.
runtime/index.d.ts
Outdated
export interface Preload { | ||
(this: PreloadContext, page: Page, session: any): object | Promise<object>; | ||
(this: PreloadContext, page: PageContext, session: any): object | Promise<object>; | ||
} |
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.
export interface Preload<Props = object, Session = any> {
(this: PreloadContext, page: PageContext, session: Session): Props | Promise<Props>;
}
Co-authored-by: Ben Cates <[email protected]>
Co-authored-by: Ben Cates <[email protected]>
@TheComputerM this PR will need to be rebased |
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.
Sorry, this might be my fault. GitHub would only allow me to format half of my proposed changes as suggestions.
runtime/index.d.ts
Outdated
@@ -28,7 +28,7 @@ declare module '@sapper/server' { | |||
ignore?: Ignore | |||
} | |||
|
|||
export function middleware(opts?: MiddlewareOptions): Handler; | |||
export function middleware<Session = unknown>(opts?: MiddlewareOptions<Session>): Handler; |
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.
I don't think this works correctly unless we also parameterize MiddlewareOptions
Fixes #1556
Before submitting the PR, please make sure you do the following
Tests
npm test
and lint the project withnpm run lint