小编Chu*_*est的帖子

已解决的承诺类型

我想使用函数的返回类型在界面上键入一个项目,如下所示:

const returnsPromise = async (): Promise<string> => {
  return Promise.resolve('I want the string type and not a Promise')
}

interface Myinterface {
  message: ReturnType<typeof returnsPromise>
}
Run Code Online (Sandbox Code Playgroud)

但是,消息的类型是Promise而不是string。人们可以得到 Promise 应该解决的类型吗?

typescript

19
推荐指数
1
解决办法
7677
查看次数

标签 统计

typescript ×1