Scenario: I have customized a third-party library for users by removing two properties from all functions in the library. I have implemented a function to achieve this, along with executing a bootstrap function if provided. Here is the code snippet:
const wrapped = <
F extends (args: any) => any,
A extends Omit<Parameters<F>[0], "fs" | "http">
>(
f: F,
pre?: (params: A) => void
): ((args: A) => ReturnType<F>) => {
return (args: A): ReturnType<F> => {
if (pre) {
pre(args);
}
return f({ fs, http, ...args });
};
};
Everything seems to be functioning correctly, highlighting the appropriate properties.
However, when utilizing a function that has been wrapped in this manner within VSCode, the intellisense output appears cluttered and complex.
To further illustrate this issue with a comprehensive example:
const wrapped = <
F extends (args: any) => any,
A extends Omit<Parameters<F>[0], "foo">
>(
f: F
): ((args: A) => ReturnType<F>) => {
return (args: A): ReturnType<F> => {
const foo = "bar"
return f({ foo, ...args });
};
};
const thirdPartyFunc = (args: {foo: string; bar: string}) => {
console.log(args.foo, args.bar);
}
const wrappedThirdPatyFunc = wrapped(thirdPartyFunc);
thirdPartyFunc({foo: "0", bar: "1"})
/**
Intellisense displays simply:
const thirdPartyFunc: (args: {
foo: string;
bar: string;
}) => void
*/
wrappedThirdPatyFunc({bar: "1"})
/**
Intellisense appears cluttered (displays Omit, includes omitted keys):
const wrappedThirdPatyFunc: (args: Omit<{
foo: string;
bar: string;
}, "foo">) => ReturnType<(args: {
foo: string;
bar: string;
}) => void>
*/
I am concerned about the potential negative user experience. Is there a modification I can make to my code to improve the intellisense output and make it resemble the original intellisense, minus the removed fields?
I am unsure of what steps to take next. This project involving generics in TypeScript is the most intricate task I have tackled so far, so I am navigating it cautiously through trial and error.