Scenario: Creating a function that takes a single object with predefined properties, where we need to destructure and assign simultaneously.
The following method works as intended:
type OBJECT_PARAM = {
pathname: string,
routePath: string
}
export const getSlugMatch = (props: OBJECT_PARAM)
: string => {
const { pathname, routePath } = props;
return "SOME_SLUG";
};
This approach, however, does not achieve the desired outcome:
export const getSlugMatch_V2 = ({pathname: string, routePath: string}): string => {
return "SOME_SLUG";
};
https://i.sstatic.net/SDIYe.png
Is there an alternative solution to this issue? How do other developers typically address this scenario? Is it necessary to explicitly define the OBJECT_PARAM
type?
It seems that the problem arises from conflicting with JavaScript's approach to renaming destructured properties. What would be the most effective workaround in this situation?