【发布时间】:2021-09-27 23:32:46
【问题描述】:
在js中是简单的例子
function thenable() {
return ['just function']
}
thenable.then = (resolve) => {
resolve('like a Promise')
}
(async function main() {
//behave like a function
const functionResult = thenable()
//behave like a Promise
const promiseLikeResult = await thenable
})()
是否可以使用打字稿键入此行为,当您调用它就像函数时它返回 string[](['just function']) 当 then 或 await 应用它返回 string ('like a承诺')?
【问题讨论】:
-
我想知道这是不是X/Y problem。为什么你希望函数做两件截然不同的事情?
标签: javascript typescript generics types