I’m getting a JSDoc syntax error
pointing to the first line of my JSDoc comment where it says /**
. Not sure what else I need to fix.
/**
* Gets any field value from a user's User collection.
* @param {number} IDType 0 = uid, 1 = username.
* @param {string} inputID the input ID, based on the IDType.
* @param {string} desiredField the desired field value.
* @returns {number, string, string} 1/0, error message, desired info.
*/
async function getUserInfo(
IDType: number
, inputID: string
, desiredField: string
): Promise<[number, string, string]> {
//...
3
Answers
Just install JSDoc Lint… while three return values appear strange to me:
And I’m probably right, because the documentation doesn’t use any comma.
Probably your return type is too complex, try with just
Promise
as documentation shows.The type statement
{number, string, string}
on the@returns
line is a syntax error.As your function is
async
, the type should be defined as{Promise<ResultType>}
. Additionally, because you are returning a tuple, you should be wrappingnumber, string, string
in square brackets –[number, string, string]
.This results in a declaration of:
Alternatively, you can also define a type for your tuple and restrict the acceptable values for the
IDType
parameter:This allows you to destructure the result and maintain the restrictive types:
You can also destructure the result directly and still preserve the types:
With the tuple type, you can also name each value in the tuple. These names are only used in your IDE and have no effect on the use of the value in JavaScript.