属性缺少类型,但这是必需的

时间:2020-01-28 15:41:01

标签: typescript

为了练习,我有以下代码:

type WarnUser = {
    wasCalled: boolean
    (warning: string): void
}

let warnUser: WarnUser = (warning: string) => {
    if(warnUser.wasCalled) {
        return
    }
    warnUser.wasCalled = true;
    alert(warning)
}

warnUser.wasCalled = false;

但是我得到的错误是:

 Property 'wasCalled' is missing in type '(warning: string) => void' but required in type 'WarnUser'.

我不确定现在如何解决此错误。你能帮我吗?

0 个答案:

没有答案