1

I have an async function that returns either a string or an array of strings. I've tried the following:

   async getAllAnnotationTimes(): Promise<string> | Promise<string[]> {
         return await this.app.client.getText(this.allAnnotationPositions);
   }

I have also used this declaration: Promise<string> | Promise<Array<string>>

Which gives this error: [ts] The return type of an async function or method must be the global Promise<T> type.

The error seems to related to the part after the or (Promise<Array<string>>)

How do I declare a promised string array?

1 Answer 1

3

You would use

Promise<string | string[]>

which is literally a promise of a union type that is either a string or an array of strings.

Sign up to request clarification or add additional context in comments.

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.