I have this example code:
function myFunction(base: string): typeof getter {
function getter(contactInfo: ContactInfo): Address[] {
...
return address;
}
return getter;
}
export default myFunction;
But when I try to do a build with declaration files, I have the following error:
error TS4060: Return type of exported function has or is using private name 'getter'. 23 function myFunction(base: string): typeof getter {
I can fix it adding the type of getter instead of typeof:
function myFunction(base: string): (contactInfo: ContactInfo) => Address[] {
function getter(contactInfo: ContactInfo): Address[] {
...
return address;
}
return getter;
}
export default myFunction;
But there are some files that are more complicated than this. There is a way to avoid this error using typeof getter instead of passing all the types?
I believe the best way to handle this is to remove the function type. TypeScript is smart enough to infer the return type of the function without an explicit notation.
function myFunction(base: string) {
function getter(contactInfo: ContactInfo): Address[] {
return address;
}
return getter;
}
export default myFunction;
// inferred type is:
// function myFunction(base: string): (contactInfo: ContactInfo) => Address[]