Allow a custom function to opt into doing all of its own argument validation
Currently, when a custom function provides type information for its parameters, Excel does some basic validation. For instance, if you say the parameter's type is `number` and the user provides `"x"`, the custom function isn't even called, Excel just shows the #NUM! error with a generic message.
This is often what you want, but for more complex and polished custom functions, make it possible for a function to opt out of that pre-validation and do all of its own validation.
One way to do that would be to have the function provide a validator function, perhaps as a property of the main custom function, but the exact mechanism isn't all that important.
Note: This partially ties into https://github.com/OfficeDev/office-js/issues/2885 that all ErrorCode codes allow custom messages, rather than just two, but they're separate issues.
3 Comments
- JamesDuleyCopper Contributor
I see. Are the proper types visible to the user anywhere? I've been using `any` quite liberally assuming the type isn't visible to the user except via this built-in validation.
- tj_aewCopper Contributor
JamesDuley - Yes, but I want to be able to give proper types to the values in the function, while still having advanced error reporting.
- JamesDuleyCopper Contributor
I believe this is possible if you mark the type as `any` rather than `number`, then you can check the type at the start of the function.