I have read about and successfully added a member to the Array interface using code like this:
interface Array<T> {
first(): T | undefined;
}
Array.prototype.first = function<T>(this: T[]): T | undefined {
return this.length > 0 ? this[0] : undefined;
};
However, if I try to do the same to the Iterable interface, it does not work:
interface Iterable<T> {
first(): T | undefined;
}
Iterable.prototype.first = function <T>(this: Iterable<T>): T | undefined {
return undefined;
}
The TS compiler returns an error about the line where I am trying to modify the Iterable prototype:
'Iterable' only refers to a type, but is being used as a value here.
Is it possible to add methods to Iterable? Thanks!