0

I have a function that returns a boolean. The function also has a property errors as an array. It is in a module.

example.js

exports["example"] = myFunc;
function myFunc(data) {
  return true;
}
myFunc.errors = ['error']

I can define the function return signature in a typescript .d.ts file;

example.d.ts

export declare function uploadedFile(data: any): boolean;

but I don't know how to define the functions errors property so that it should return a string array?

export declare function uploadedFile(data: any): boolean;
export declare property uploadedFile.errors: Array<string>; // ??
myol
  • 8,857
  • 19
  • 82
  • 143
  • possible duplicate of https://stackoverflow.com/questions/12766528/build-a-function-object-with-properties-in-typescript? – Bergi Aug 09 '21 at 15:22

2 Answers2

1

You can declare it as an object with a call signature:

export declare var uploadedFile: {
  (data: any): boolean;
  errors: string[];
};
Bergi
  • 630,263
  • 148
  • 957
  • 1,375
0

To declare the property errors you can change the second declaration to namespace like this:

export declare function uploadedFile(data: any): boolean;
export declare namespace uploadedFile {
    errors: Array<String>;
}
henriale
  • 1,012
  • 9
  • 21