TypeScript issue when using a custom listen handler #16726
Replies: 6 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.
-
I am following the guide to setup SSR for my TypeScript-based project:
https://quasar.dev/quasar-cli-vite/developing-ssr/ssr-webserver#serverless
The problem appears to be the
ssrListen
wrapper, which declares the following type for the callback:It does not allow the type
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.
All reactions