Skip to content

Commit 2c2087d

Browse files
authored
Fix(flow): Allow unnamed parameters (#674)
This allows `type T = number => string`. Previously we were only handling `type T = (x: number) => string` correctly. Followup to #672 that: - Adds a test fixture - Fixes lint errors
1 parent 5bd42d6 commit 2c2087d

6 files changed

+991
-3
lines changed

lib/flow_doctrine.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ function flowDoctrine(type/*: Object */)/*: DoctrineType*/ {
100100
params: type.params.map(param => {
101101
let name = '';
102102
if (param.name && param.name.name) {
103-
name = param.name.name;
103+
name = param.name.name;
104104
}
105105
return {
106106
type: 'ParameterType',
107-
name: name,
107+
name,
108108
expression: flowDoctrine(param.typeAnnotation)
109109
};
110110
}),

lib/output/util/format_type.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function formatType(getHref/*: Function*/, node/*: ?Object */) {
119119
return [link(node.name, getHref)];
120120
case Syntax.ParameterType:
121121
if (node.name) {
122-
result.push(t(node.name + ': '));
122+
result.push(t(node.name + ': '));
123123
}
124124
return result.concat(formatType(getHref, node.expression));
125125

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @flow
2+
3+
'use strict';
4+
5+
/** x */
6+
let x: T => string;
7+
8+
/** x2 */
9+
let x2: (a: T) => string;
10+
11+
/** T */
12+
type T = string[] => {num: number};
13+
14+
/** T2 */
15+
type T2 = (a: string[]) => {num: number};

0 commit comments

Comments
 (0)