A
A
Andrey Suha2020-05-27 18:15:27
typescript
Andrey Suha, 2020-05-27 18:15:27

How to resolve assignment?

Hello everyone

There is an object with this type

private handlers: { [key: string]: Function | Function[] } = {};


next in the method I try to execute the following code

if(Array.isArray(this.handlers[handlerId])) this.handlers[handlerId].push(handler);
 else {
    let handlers = [ this.handlers[handlerId], handler ];
    this.handlers[handlerId] = handlers;
 }


I get these errors

Sbm9Quv.png

for the line
if(Array.isArray(this.handlers[handlerId])) this.handlers[handlerId].push(handler);


and

4NpCoqD.png

on the line

this.handlers[handlerId] = handlers;

How do I tell the compiler that I took care of the type checking myself, or how do I suppress these errors?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Kuznetsov, 2020-05-27
@andreysuha

you can try this: link

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question