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

add flow exceptions for polymorphic types - Ref #109 #118

Merged
merged 1 commit into from
Jun 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -297,6 +297,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