I have the following example:
class Uncle {
constructor(public name : string) { }
talk() {
return "Hello my name is " + name;
}
}
let p : Uncle = new Uncle("Jo");
console.log(p.talk());
For certain variable names, typescript (right now Version 2.1.4) will not complain that they are not defined in your program (In the method talk, name is being used without this.). name
is one of those.
If I rename the variable to, say, firstName
, the compiler complains rightfully...
error TS2663: Cannot find name 'firstName'. Did you mean the instance member 'this.firstName'?
Same goes for e.g. window, which is apparently assumed to exist.
My question(s) are:
- Which variable names are assumed to exist and why?
- Can that behaviour be changed (e.g. in some linters you can state which variables you expect to be globally available)?