-
Notifications
You must be signed in to change notification settings - Fork 116
Open
Labels
Description
Expected behavior
When using a type in parentheses, the function metadata should be able to be generated correctly. This is specifically needed for arrays.
Current behavior
When I run the metadata tool, it returns an error:
Type doesn't match mappings (6, 23)
Type doesn't match mappings (4,14)
Steps to Reproduce
Create a custom function file with the following definition:
/**
* Do the thing
* @customfunction
* @returns {(string | number)[]} The result
*/
export function foo(): (string | number)[] {
return [];
}Run the metadata tool against the above file.
However, this also occurs for essentially any type wrapped in parentheses. For example, this code (although silly) also demonstrates the same issue:
/**
* Do the thing
* @customfunction
* @returns {(string)} The result
*/
export function foo(): (string) {
return [];
}Diagnosis
The specific issue occurs here:
| node = arrayType.node; |
Where the type of the expression for the array is ParenthesizedType. A naive fix would be something like:
node = arrayType.node;
if (node.kind=== ts.SyntaxKind.ParenthesizedType) {
node = node.type;
}
However since it also impacts non array types, perhaps it can try and unwrap the type at the end:
node = unwrapNode(node);
type = TYPE_MAPPINGS[node.kind];
if (!type) {
extra.errors.push(logError("Type doesn't match mappings", typePosition));
}
// This could be extended to account for other weirdness
const unwrapNode = (node: TypeNode): TypeNode => {
let curr = node;
while (curr.kind === ts.SyntaxKind.ParenthesizedType) {
curr = (curr as ParenthesizedTypeNode).type;
}
return curr;
};Context
- Operating System: Win 11
- Node version: 20.14.0
- Typescript: 5.8.3
- Office version: N/A
- Tool version: 2.1.2