In a discussion on extending the Static String Class in Typescript, I came across an example showing how we can extend existing base classes in typescript by adding new methods.
interface StringConstructor {
isNullOrEmpty(str:string):boolean;
}
String.isNullOrEmpty = (str:string) => !str;
This example worked perfectly for me. However, when it came to creating a generic interface and adding a new method like 'contain()' to an Array, I faced some challenges. Here's what I tried:
//1
interface Array<T> {
contain(item: T): boolean;
}
//2
?????? = (item: T) => {
// ....
return true;
};
After adding the first step, I saw 'contain' method appearing in VS intellisense, but I couldn't figure out where to actually implement this method. Any suggestions?