Can you not return values from async functions?


[ts] The return type of an async function or method must be the global Promise<T> type. [1064]

I’m getting this message after setting the return type in the asdocs but it seems to be working:

 * Get artboard preferences
 * @param {Artboard} artboard
 * @returns {String}
async function getPreferences(artboard) {
    return "test";

var preferences = await getPreferences(artboard);
log("Preferences: " + preferences); // "test"

Can you not return values from async functions? Is the TS warning incorrect? It seems to be working.


The TS warning is correct, since you’ve specified the return type to be of the type String, but it in fact is a Promise<String> since the function is asynchronous.

Therefore, it is working since it’s only linting your Doc comment, but it warns you that the asynchronous function does – in fact – not return a string but a promise for a string (and therefore, things like autocompletion, linting etc. won’t work as expected).

Hope this helps,