Best explained in code:
const ROUTE_PARAMS = {
userId: 'userId',
companyId: 'companyId',
};
// Is this somehow possible?
// `typeof` is obviously not the right tool here, just used as an example.
function buildRoute(typeof ROUTE_PARAMS): string;
// Result should be similar to:
function buildRoute2(userId: string, companyId: string): string;
// The function should be called like this:
buildRoute('some-user-id', 'some-company-id');
// I don't want the function to accept only 1 object like this:
buildRoute({ userId: 'some-user-id', companyId: 'some-company-id' });
The idea is to have the route params of buildRoute somehow dynamically "bound" to the object.
When defining the function params "manually" (like in buildRoute2), I always have to keep them in sync when changing properties of ROUTE_PARAMS...
Additional Info
I'll try to add some information as my question above does not seem to be sufficiently clear:
- I'm explicitly looking for a way to "type" this function from an object like the one shown above (
ROUTE_PARAMS). - I can't change this to some other structure (tuple type, some kind of array, ...) as that would require refactoring of other parts in my code which work with the object
ROUTE_PARAMS. - The function should except each object property as a single input parameter (i.e. function arity === number of object properties).
I don't want the function to accept all properties packed into 1 object ( & examples above).