Allow a custom function to opt into doing all of its own argument validation

Allow a custom function to opt into doing all of its own argument validation
0

Upvotes

Upvote

 Oct 10 2022
3 Comments (3 New)
New

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 this request that all ErrorCode codes allow custom messages, rather than just two, but they're separate issues.

Comments
Copper 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.

Copper 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.

Copper 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.