diff --git a/index.js b/index.js index 7b742494..46e402a5 100644 --- a/index.js +++ b/index.js @@ -176,6 +176,18 @@ function monkeypatch() { } } + function visitTypeParameters(typeParameters) { + var params = typeParameters.params; + + // visit bounds on polymorphpic types, eg; `Foo` in `fn(a: T): T` + for (var i = 0; i < params.length; i++) { + var param = params[i]; + if (param.typeAnnotation) { + visitTypeAnnotation.call(this, param.typeAnnotation); + } + } + } + function checkIdentifierOrVisit(node) { if (node.typeAnnotation) { visitTypeAnnotation.call(this, node.typeAnnotation); @@ -249,6 +261,7 @@ function monkeypatch() { var typeParamScope; if (node.typeParameters) { typeParamScope = nestTypeParamScope(this.scopeManager, node); + visitTypeParameters.call(this, node.typeParameters); } if (node.returnType) { checkIdentifierOrVisit.call(this, node.returnType); diff --git a/test/non-regression.js b/test/non-regression.js index ee8c03a9..395a6de5 100644 --- a/test/non-regression.js +++ b/test/non-regression.js @@ -222,13 +222,13 @@ describe("verify", () => { ); }); - it("type parameters", () => { + it("type parameter bounds", () => { verifyAndAssertMessages( unpad(` import type Foo from 'foo'; import type Foo2 from 'foo'; - function log(a: T1, b: T2) { return a + b; } - log(1, 2); + function log(a: T1, b: T2) { return a + b; } + log(1, 2); `), { "no-unused-vars": 1, "no-undef": 1 }, []