How to create ErrorEvent in TypeScript?

According to this post

How to properly initialize en ErrorEvent in javascript?

You must create EventErrorusing this code:

var error = new ErrorEvent('oh nose', {
    error : new Error('AAAHHHH'),
    message : 'A monkey is throwing bananas at me!',
    lineno : 402,
    filename : 'closet.html'
});

However, if you try this on the TypeScript playground:

https://www.typescriptlang.org/play/#src=var%20error%20%3D%20new%20ErrorEvent ('oh% 20nose'% 2C% 20% 7B% 0A% 20% 20% 20% 20error% 20 % 3A% 20new% 20Error ('AAAHHHH')% 2C% 0A% 20% 20% 20% 20message% 20% 3A% 20'A% 20monkey% 20is% 20throwing% 20bananas% 20at% 20me!% 2C% 0A% 20 % 20% 20% 20lineno% 20% 3A% 20402% 2C% 0A% 20% 20% 20% 20filename% 20% 3A% 20% 0A% 7D 'closet.html')% 3B

It says Supplied parameters do not match any signature of call target.

Even this simple example does not compile:

var error = new ErrorEvent('oh nose');

I tried to figure this out by looking at the type definition

https://github.com/Microsoft/TypeScript/blob/master/lib/lib.es6.d.ts#L9612

.

EventError TypeScript?

+4
1

lib.es6.d.ts .

TypeScript github, lib.es6.d.ts :

// add this interface
interface ErrorEventInit {
    // ...put the properties here...
}

// edit this declare var new signature
declare var ErrorEvent: {
    new(type: string, eventInitDict?: ErrorEventInit): ErrorEvent;
    prototype: ErrorEvent;
}
+3

Source: https://habr.com/ru/post/1662655/


All Articles