const isNull = (v:any) : v is null => v === null;
const isString = (v:any) : v is string => typeof v === 'string';
const or = <T extends Function,K extends Function>(fn1:T, fn2:K) => (first: any): first is ReturnType<T> | first is ReturnType<K> => (fn1(first) || fn2(first))
执行
const conditon = or(isNull, isString);
condition(v)
如何 first is ReturnType<T> | first is ReturnType<K>
获取不是返回函数的类型,而是给定的类型 v is null
这样在函数的描述中传递一个值时,它应该是first is string | null
我找到了这个答案
有一个沙箱
见t4。
缺少功能本身的实现-超出了问题的范围。