Open falsandtru opened 6 years ago
I think it allows string
too. see https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout
Then this is valid, right?
declare function setTimeout(handler: ((...args: any[]) => void) | string, timeout?: number, ...args: any[]): number;
Be aware, that if you pass a string
it is equivalent to eval
.
Douglas Crockford warned of this.
Perhaps this second declaration could go into @RyanCavanaugh's proposed Annex B :wink:
Looking at some of the new features that Typescript provides, I'd expect the following to be a better more specific definition
declare function setTimeout<T>(handler: string | ((...args: T[]) => void), timeout?: number , ...params: T[]) => number;
Hi, no news about this?
We hit this problem. TypeScript does not check this code:
function f(x: number) {
x.toExponential()
}
setTimeout(f, 100)
// ~ should be an error!
Fix too lax typings.
TypeScript Version: master
Expected behavior:
Actual behavior: