After creating a Union type of supported methods, the goal is to verify if a specific method belongs to the set of supported methods and then execute it dynamically. One commonly used approach is to use an array containing the names of the supported methods and utilize methods such as includes to perform the check. However, I am curious if it is possible to achieve the same outcome through type checking.
import * as mathFn from './formula/math';
type SupportedMathFunction = keyof typeof mathFn;
//'fnA'| 'fnB' | ...
For instance, the desired syntax would be:
if( methodName is SupportedMathFunction){
//do something
}