2

Its seem that typescript have its own windows implementation.

How exactly i can set windows.onerror ?

The only "documentation" I found is

onerror: ErrorFunction; 
interface ErrorFunction {
   (eventOrMessage: any, source: string, fileno: number): any; 
}

1 Answer 1

2

The objective of the definition you are showing is to provide the developer with intellisense + typesafety. You would use it like you normally would want to in javascript:

window.onerror= function(eventOrMessage: any, source: string, fileno: number){
    // place your body here 
};

See it on typescript playground.

More:

If you try to assign it a wrong function you will get an error:

// Error: wrong type for fileno
window.onerror= function(eventOrMessage: any, source: string, fileno: string){

};

You could omit any of the arguments since functions with lesser arguments are type compatible e.g. the following is valid typescript:

window.onerror= function(callitWhaever_ButItWillTakeTheEventOrErrorMessage){
    // place your body here 
};
Sign up to request clarification or add additional context in comments.

2 Comments

+1 - I agree with using auto completion to discover the signatures. Bear in mind that this isn't TypeScripts "own implementation" - you are still calling the browser implementation so the normal documentation for window.onerror applies.
bassarat, buddy! Your playground link no longer works in TS 0.9.5 and I can't figure out how to fix it. :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.