TypeScript issue when using a custom listen handler #16726
-
|
I am following the guide to setup SSR for my TypeScript-based project: The problem appears to be the export type SsrListenCallback = (
params: SsrListenParams
) => Promise<Server>;It does not allow the type { handler: any }to be returned. Am I doing something wrong, or is this a bug in the type declarations? I tried to submit this as an issue but the StackBlitz projects suggested for forking when submitting an issue do not use TypeScript. |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 8 replies
-
|
Actually that entire sample code appears to be non-functional: export async function listen ({ app, port, ssrHandler }) {
if (process.env.DEV) {
await isReady()
return await app.listen(port, () => {
if (process.env.PROD) {
console.log('Server listening at port ' + port)
}
})
}
else { // in production
// "ssrHandler" is a prebuilt handler which already
// waits for all the middlewares to run before serving clients
// whatever you return here is equivalent to module.exports.<key> = <value>
return { handler: ssrHandler }
}
}Because the function is marked as |
Beta Was this translation helpful? Give feedback.
-
|
You can only annotate the types of the parameters in the 'listen' function and remove the 'async' identifier if you don't need it. import {
ssrListen,
} from 'quasar/wrappers';
type SsrListenParams = Parameters<Parameters<typeof ssrListen>[0]>[0];
export const listen = ({ app, port, isReady, ssrHandler }: SsrListenParams) => {
if (process.env.DEV) {
isReady();
return app.listen(port, () => {
if (process.env.PROD) {
console.log('Server listening at port ' + port);
}
});
} else {
// 生产环境下:
return { handler: ssrHandler };
}
}; |
Beta Was this translation helpful? Give feedback.
-
|
The return type should be |
Beta Was this translation helpful? Give feedback.
-
I hope you can also export the |
Beta Was this translation helpful? Give feedback.
-
I made a mistake 😂. It seems to be work well. But,why it can be imported without been exported🤔 |
Beta Was this translation helpful? Give feedback.
-
|
Enhancements are coming in q/app-webpack v4.0.0-beta.17 and q/app-vite v2.0.0-beta.16 |
Beta Was this translation helpful? Give feedback.
-
|
Further improvements were made by #18052 and #18050. It's been released on |
Beta Was this translation helpful? Give feedback.






Further improvements were made by #18052 and #18050. It's been released on
@quasar/app-vite v2.3.0and@quasar/app-webpack v4.3.0a while back. So, this issue should be completely eliminated now.