在 TypeScript 中,可以使用 'Promise' 表示一个函数返回值为 Promise 的函数。因此,要将 TypeScript 类型函数返回值为 Promise,可以在函数签名中使用 'Promise',其中 T 表示 Promise 的结果类型。例如:

export type UserActions = {
    login({ commit }: ActionContext<UserState, RootState>, LoginParm: LoginParm): Promise<Result>
}

这里,'login()' 函数返回值为 Promise,表示该函数将返回一个 Promise,该 Promise 将解析为一个 Result 类型的值。

TypeScript 函数返回值为 Promise 的类型定义

原文地址: https://www.cveoy.top/t/topic/njDA 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录