TypeScript mixed type implementation

Mixed types are explained on http://www.typescriptlang.org/Handbook#interfaces. Because these are very useful for creating JS input-I wonder if it is possible to define an implementation For example, the class of JS. Such an interface:

interface Counter {
(start: number): string;
interval: number;< br /> reset(): void;
}

If not, then maybe just create objects of that type? how about it?

I wonder if it’s possible to define a class implementing

No

If not then maybe it’s possible to create just an object of that type?

Yes. Type assertion (or whatever) will be used:

interface Counter {
(start: number): string;
interval: number;< br /> reset(): void;
}function getCounter():Counter{ var counter = function(start:number){}; counter.interval = 123; counter.reset = function(){ }; return counter;}

The mixed types are explained on the http://www.typescriptlang.org/Handbook#interfaces website. Because these are very important for creating JS input Useful-I want to know if it is possible to define a class that implements for example JS. Such an interface:

interface Counter {
(start: number): string ;
interval: number;
reset(): void;
}

If not, then it is possible to only create objects of this type? how about it?

I wonder if it’s possible to define a class implementing

No

If not then maybe it’s possible to create just an object of that type?

Yes. Type assertions (or whatever) will be used:

interface Counter {
(start: number): string;
interval: number;
reset(): void;
}function getCounter():Counter{ var counter = function(start:number){}; counter.interval = 123; counter.reset = function(){}; return counter;}

Leave a Comment

Your email address will not be published.