Disclaimer: I'm working on a competing tool
If a particular function can be tied to particular variable from scoping block, then the function is not entirely useful. On the other hand, if a function is general and has the same argument name as variable from scoping block, which is going to be passed in, mentally it is difficult to analyse the function without thinking about the variable which may shadow bugs in function. E.g. square root function may omit negative argument check, because variable from scoping block is always positive.
Instead of knowing scoping rules I advocate for distinct variable names, so scoping rules (name shadowing) do not even come into play.
function Person(name) {
var person = this;
person.name = name;
}
var person = new Person("Jon Doe");
alert("Welcome " + person.name);
person.name = "Harry Houdini";
// ES6 example:
var messages = people.map( person => person.name += " is a rock star" )As you work on this, do you know if the refactoring tools would fully work with my code typed with Flow instead of TypeScript?
(I use the official flow-for-vscode extenstion, idk if it's relevant)
Edit: Ok I just tried and it works, even with the extension disabled.
type Foo = {
a: boolean,
b: string,
}
var foo: Foo = {
a: true, // Find all references on "a" here...
b: "hello"
};
foo.a = false;
bar(foo);
function bar(obj: Foo) {
obj.a = false; // Found it.
}- If you don't have any calls to the function yet (i.e. "bar(foo)" wasn't there above), then there is nothing to infer from, so you have no idea what the type is at this point (other than by the use of the parameter inside the function).
- Is your call-site wrong? If the parameter type is explicit, this is easily checked. If not, then again you can only go by what the function does with it. (Which may not be much help if it's something like "RestAPI.post(JSON.stringify(theParamInQuestion))" ).
There is some support for JsDoc in the engine, so code like the below will work:
Full disclaimer: I work on these tools.