Closed
Description
Steps to reproduce
Using TypeScript:
This is typed correctly, but does not work:
// options
router: (req) => {
const newTarget = {
host: req.context.host || 'localhost',
protocol: req.context.protocol || 'https:',
port: req.context.port || 8080
};
return `${target.protocol}//${host}:${port}`;
},
The return value is typed incorrectly, but this works:
// options
router: (req) => {
const newTarget = {
host: req.context.host || 'localhost',
protocol: req.context.protocol || 'https:',
port: req.context.port || 8080
};
return newTarget;
},
Expected behavior
router
return type seems like it should be something like:
interface RouterReturnValue {
host: string;
protocol: 'http:' | 'https:'; // the : is required!
port: number;
}
Actual behavior
Using a string doesn't work to dynamically set the target
.
Workaround
router: (req) => {
const newTarget = {
host: req.context.host || 'localhost',
protocol: req.context.protocol || 'https:',
port: req.context.port || 8080
};
return (newTarget as unknown) as string;
}
Reproducible Demo
I'm not sure yet how to make a standalone example but I can try if needed.
Metadata
Metadata
Assignees
Labels
No labels