0

我正在使用 Typescript 0.9.1.1,我似乎遇到了这个简单问题的错误:

function doSomething(): void {
    console.log("Printing something");
}

window.setTimeout(() => {
    doSomething();
}, 3000);

它说我有一个Unresolved Function or Method setTimeOut(). 我查看了 Typescript lib.d.ts 文件,这就是我发现的:

declare function setTimeout(expression: any, msec?: number, language?: any): number;

MDN 上的这篇文档中,我也可以说我说得对。那么,为什么 TypeScript 会给我带来问题?

这是我的 lib.d.ts 文件的样子: 在此处输入图像描述 在此处输入图像描述

4

1 回答 1

1

I'm using 0.9.1.1 and the signature is different to the one you have posted:

declare function setTimeout(handler: any, timeout?: any, ...args: any[]): number;

And everything compiles fine to:

function doSomething() {
    console.log("Printing something");
}

window.setTimeout(function () {
    doSomething();
}, 3000);

Where are you looking for that lib.d.ts?

In any case, you shouldn't get the error because the signature you posted only requires the expression (any) and you are supplying an msec (number) of the correct type - so your call looks compatible with that.

于 2013-08-22T19:23:48.147 回答