I am looking to customize the typing of an npm library by adding an index signature to a function. The function itself is fairly basic:
export function foo(input) {
return Number(input);
}
Currently, its typing in the .d.ts
file looks like this:
export default function foo(input: string): number | null;
I want to extend this function with additional properties, for example:
foo['something'] = 2;
My goal is to modify the .d.ts
file so that I can add any property to the function, not just predefined ones like 'something'. To achieve this, I need it to have an index signature of [index: string]: number;
. While I've come across solutions for adding specific properties, I haven't found one that allows for any string as a key.