【发布时间】:2019-06-20 07:29:45
【问题描述】:
我在将异步(箭头)函数用作类型/接口属性的语法上遇到问题。 我已经做了一些研究,但除了这个https://github.com/Microsoft/TypeScript/issues/22035之外没有发现太多 这对我的情况不是 100% 准确,但总比没有好。而且还是不适合我...
这是关于我在声明中的代码(简化):
export type MyType = {
att1: string;
funct: async (param1: string, param2: string) => Promise<string[]>;
};
我在哪里使用它(例如,不是我的实际代码):
import { MyType } from "./MyType";
const myObject: MyType = {
att1: "First attribute";
funct: async (param1: string, param2: string): Promise<string[]> => {
// Code below is an example, in my case it's a database querying
// But anyway, it's something async
return new Promise((resolve, reject): void => {
setTimeout((): void => {
resolve(["string1", "string2"]);
}, 5000);
});
};
};
TypeScript 转译器说它找不到名称“异步”。 如何判断 MyType 中的函数“funct”是异步的?我需要在其中使用 await...
【问题讨论】:
标签: javascript node.js typescript typescript-typings