global.setTimeout instead of
During this conversion to TypeScript I’ve run into a minor few issues, but this
seemed worth sharing. Basically I needed to use a
setTimeout in my code to
defer an operation, but the available types of
were confusing. Which is correct? At first it appeared neither was correct since
I was receiving the following error
[ts] Type 'number' is not assignable to
type 'Timer | null'.
let timer:NodeJS.Timer; timer = global.setTimeout(myFunction, 1000);
global.setTimeout (the equivalent of
window, in node.js) all
was cleared up and the TypeScript compiler was happy once again.