0

If I add this line to my code

if (window.applicationCache) {
    applicationCache.addEventListener('updateready',
        window.location.reload);
}

I get this weird error:

/home/matej/archiv/2014/projekty/zalmy/zalmy.ts(58,22): error TS2082:
 Supplied parameters do not match any signature of call target:
    Could not apply type '"downloading"' to argument 1 which is
    of type 'string'.
/home/matej/archiv/2014/projekty/zalmy/zalmy.ts(58,22): error TS2087:
    Could not select overload for 'call' expression.
make: *** [zalmy.js] Error 1

What's going on? Is it a bug in tsc? (using the latest typescript 0.9.5).

mcepl
  • 2,688
  • 1
  • 23
  • 38

1 Answers1

0

Wrap it up in a function :

if (window.applicationCache) {
    applicationCache.addEventListener('updateready', () => {
        window.location.reload();
    });
}

Reason is that the argument for event listener (ev:Event) is different from the optional argument for reload (boolean)

basarat
  • 261,912
  • 58
  • 460
  • 511
  • You are obviously right, but that makes me feel there are severe limitations with strict-type languages. One has to do inelegant nonsenses like this. Hmm. – mcepl Feb 25 '14 at 17:51
  • 4
    @mcepl Without TS you were actually calling location.reload with true (the event object is truthy) and invalidating your cache. Was that intentional? – basarat Feb 25 '14 at 23:28