Skip to content
This repository has been archived by the owner on Aug 18, 2021. It is now read-only.

Commit

Permalink
Merge pull request #118 from hzoo/poly-types
Browse files Browse the repository at this point in the history
add flow exceptions for polymorphic types (<A>) - Ref #109
  • Loading branch information
hzoo committed Jun 3, 2015
2 parents 270cfbd + 0ebdf8b commit 270fd53
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ function monkeypatch() {
if (node.typeAnnotation) {
visitTypeAnnotation.call(this, node.typeAnnotation);
} else if (node.type === "Identifier") {
// exception for polymorphic types: <T>, <A>, etc
if (node.name.length === 1 && node.name === node.name.toUpperCase()) {
return;
}
this.visit(node);
} else {
visitTypeAnnotation.call(this, node);
Expand Down
20 changes: 20 additions & 0 deletions test/non-regression.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,26 @@ describe("verify", function () {
);
});

it("polymorphpic types #109", function () {
verifyAndAssertMessages([
"export default function groupByEveryN<T>(array: Array<T>, n: number): Array<Array<?T>> {}"
].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 },
[]
);
});

it("types definition from import", function () {
verifyAndAssertMessages([
"import type Promise from 'bluebird';",
"type Operation = () => Promise;",
"x: Operation;"
].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 },
[]
);
});

it("1", function () {
verifyAndAssertMessages(
[
Expand Down

0 comments on commit 270fd53

Please sign in to comment.