Monday, February 17, 2014

TypeScript: window.onerror

As JavaScript applications grow larger and larger, error handling becomes more important. One of the places where you can add error handling is by subscribing to the window.onerror event handler.

According to the documentation, the following parameters are expected:

  • Error message (string)
  • Url where error was raised (string)
  • Line number where error was raised (number)

When I tried to implement this inside TypeScript, I got into trouble:

image

TypeScript gave me the following error message:

Cannot convert ‘’'(message: string) => void’ to ‘ErrorEventHandler’: Call signatures of types ‘(message: string) => void’ and ‘ErrorEventHandler’ are incompatible: Type ‘String’ is missing property ‘timeStamp’ from type ‘Event’

No clue what this message is telling me Verwarde emoticon. In the end I got it working by using the following signature:

No comments: