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>; // ??
1

2 Answers 2

1

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

export declare var uploadedFile: {
  (data: any): boolean;
  errors: string[];
};
Sign up to request clarification or add additional context in comments.

Comments

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>;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.