Skip to content

typing and documentation for router's return value seems to be incorrect #408

Closed
@dylang

Description

@dylang

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions