V
V
Vitaly2016-12-15 20:59:46
typescript
Vitaly, 2016-12-15 20:59:46

How to extend class prototype in TS?

Need something like this (error - foo not found):

interface String {
   foo(): number;
}

String.foo= function() {
   return 0;
}

String.prototype.foo= function() {
   return 0;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan Lopatin, 2016-12-16
@vitali1995

declare global {
    interface String {
        foo(): number;
    }
}

String.prototype.foo = function () {
    return 0;
};

Description here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question