我试图将类型附加到javascript的函数库上。但是,当我尝试实现函数'go1‘时,如果目标是instanceof Promise,则在评估目标之后对'then’链应用fn(任何函数)时,我遇到了一个问题 在我看来,没有什么问题,有足够的线索来推断fn的类型。Promise.resolve("string")
const c = go1(promiseString,x=>x.Lowercase()) // emit er
类型记录似乎能够推断递归函数的类型: * Typescript correctly infers the type is * const referencesSelf: () =>ellipsis means recursion of the functionconst referencesSelf = () => {};
但是,无法推断具有递归性质的
} 然后像这样调用这个函数: function bar() { if (a === undefined) { }
return a; // TypeScript infers a as number (good!)} 因为函数foo返回元组(number, undefined)或(undefined, number),所以在没有通过a ===