How can I type the this
argument when my function receives it?
import { generatePath } from 'react-router-dom';
type generatePathParamsType = Parameters<typeof generatePath>[1];
// Following type definition of 'this' is not working
const generatePathFactory = function (this: typeof ENV_DASHBOARD) {
return function (args: generatePathParamsType = {}) {
// 'this' implicitly has type 'any' because it does not have a type annotation.
return generatePath(this.PATH, args);
};
};
const ENV_DASHBOARD = {
PATH: "/dashboard/:environmentId",
generatePath: generatePathFactory.apply(this),
TITLE: "Dashboard"
};
console.log(ENV_DASHBOARD.generatePath({ environmentId: "1" })); // '/dashboard/1'