I want to create an interface like this:
interface Show { show(): string; } function doit(s: Show) { return 'Showed: ' + s.show(); }
Then we can use it with a new class:
class Foo { s: string; constructor(s: string) { this.s = s; } show() { return 'Foo with "' + this.s + '"'; } } console.log(doit(new Foo('hello')));
I would like to do the same for Number s. In simple JavaScript, I could make the Number type, for example, execute this interface with:
Number.prototype.show = function() { return '' + this; }
But TypeScript does not allow me to do this:
show.ts(18,18): error TS2094: The property 'show' does not exist on value of type 'Number'.
Is there any way to do this?
javascript interface typescript
limp_chimp Apr 26 '14 at 4:15 2014-04-26 04:15
source share