-
-
Notifications
You must be signed in to change notification settings - Fork 208
Flow generic class members #123
Comments
I guess that last patch didn't cut it haha. Kind of unrelated but is the feature called "generic types?" #109 (comment) used "polymorphic types" and that's what the flow docs were saying http://flowtype.org/docs/functions.html#polymorphic-functions. Generics makes sense too but I was just wondering. |
Ah yeah, Flow uses "polymorphic types" to describe this. The concepts are more or less interchangeable in this context though :) |
Ah so the reason is because I'm just ignoring/not visiting the those types. Looks like we'll need to create a variable in the scope whenever there is a polymorphic type to fix this |
That sounds like a great way to handle this. function and class are the places polymorphic types can be introduced, you could just create a new scope for each and supply the polymorphic types in that scope |
Might be worth looking into shimming |
@leebyron Kind of doing something like that now for type definitions https://github.com/babel/babel-eslint/blob/master/index.js#L249-L263 function createScopeVariable (node, name) {
this.currentScope().variableScope.__define(name,
new Definition(
"Variable",
name,
node,
null,
null,
null
)
);
}
referencer.prototype.TypeAlias = function(node) {
createScopeVariable.call(this, node, node.id);
...
} @sebmck Ok but will probably need some guidance 😄 Looks like it's https://github.com/babel/babel/tree/master/src/babel/traversal/scope? |
Was just an idea 😄 It's likely non-trivial ( |
This adds a special escope Scope when function, class, and typealias definitions include typeParameters which includes those parameters for reference, but is write-through to it's parent when encountering new variables. This is a little weird, but seems as good as we can while monkey-patching escope. This also fixes some tests which had invalid flow but were written to expect no errors. Fixes babel#123
This adds a special escope Scope when function, class, and typealias definitions include typeParameters which includes those parameters for reference, but is write-through to it's parent when encountering new variables. This is a little weird, but seems as good as we can while monkey-patching escope. This also fixes some tests which had invalid flow but were written to expect no errors. Fixes babel#123
Fixes flow type scoping issues - fixes #123
Fixes flow type scoping issues - fixes babel/babel-eslint#123
babel-eslint currently produces "unused" errors for valid flow-typed javascript when using generics with class members:
Most uses of the generic seem to be fine, but typing the class members fails lint.
The text was updated successfully, but these errors were encountered: