This project is read-only.

how can you extend native objects in ts.

Topics: General
Oct 16, 2012 at 11:42 AM
Edited Oct 16, 2012 at 11:43 AM

Lets say i want to extend String how can i do this in typescript?


interface String { 
	uniqueID(): string;

var UID =;
String.prototype.uniqueID = function() : string { 
	return (UID++).toString(36);

String.prototype.uniqueID = function () { 
        // do stuff

This will not compile, so what am i doing wrong?

Oct 16, 2012 at 5:07 PM

There's also some guidance on how to do this here:  There is also currently a bug when extending built-ins that we're currently working on fixing.