Closed
Description
TypeScript Version: 2.0.0 beta with "noImplicitThis": true
Code
interface String {
contains(this: string, str: string): boolean;
}
// OK
String.prototype.contains = function (this: string, str: string): boolean {
return this.indexOf(element) != -1;
};
//Error: 'this' implicitly has type 'any' because it does not have a type annotation.
String.prototype.contains = function (str: string) {
return this.indexOf(str) != -1;
};
// OK
String.prototype.contains = function (str): boolean {
return this.indexOf(str) != -1;
};
// OK
String.prototype.contains = function (str) {
return this.indexOf(str) != -1;
};
Look like once you type some parameters you have to type all of them, including the this
.
What's the reason?