
4,394 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I'm developing an Excel add-in with a suite of custom functions. Many take arrays as input, and I would like said functions to return valid results for valid inputs and #VALUE for invalid inputs, on a per-cell basis. My question is, how do I declare the function in TypeScript?
This compiles:
export function doSomething(values: number[][]): any[][]
return values.map(rowValues =>
rowValues.map(value =>
value >= 0 ? String(value) : new CustomFunctions.Error(CustomFunctions.ErrorCode.invalidValue, "No negatives!")
)
);
}
This doesn't:
export function doSomething(values: number[][]): (string | CustomFunctions.Error)[][]
return values.map(rowValues =>
rowValues.map(value =>
value >= 0 ? String(value) : new CustomFunctions.Error(CustomFunctions.ErrorCode.invalidValue, "No negatives!")
)
);
}
The latter is better TypeScript, in that it enforces type safety on the results, but I get the following error in the task pane:
functions.ts Type doesn't match mappings (90,116)
How do I declare the return type for functions that can return errors in an array?