Skip to content

Commit

Permalink
fix: Flow annotations should override any other type information
Browse files Browse the repository at this point in the history
Fixes #755
  • Loading branch information
tmcw committed Jul 27, 2017
1 parent de48092 commit 45c382a
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/infer/params.js
Expand Up @@ -95,6 +95,16 @@ function paramToDoc(
const autoName = '$' + String(i);
const prefixedName = prefix + '.' + param.name;

if (param.typeAnnotation) {
return {
title: 'param',
name: prefix ? prefixedName : param.name,
anonymous: true,
lineNumber: param.loc.start.line,
type: flowDoctrine(param)
};
}

switch (param.type) {
case 'AssignmentPattern': {
// (a = b)
Expand All @@ -121,7 +131,7 @@ function paramToDoc(
title: 'param',
name: autoName,
anonymous: true,
type: (param.typeAnnotation && flowDoctrine(param)) || {
type: {
type: 'NameExpression',
name: 'Object'
},
Expand All @@ -137,7 +147,7 @@ function paramToDoc(
title: 'param',
name: prefixedName,
anonymous: true,
type: (param.typeAnnotation && flowDoctrine(param)) || {
type: {
type: 'NameExpression',
name: 'Object'
},
Expand All @@ -161,7 +171,7 @@ function paramToDoc(
title: 'param',
name: autoName,
anonymous: true,
type: (param.typeAnnotation && flowDoctrine(param)) || {
type: {
type: 'NameExpression',
name: 'Array'
},
Expand Down Expand Up @@ -196,9 +206,6 @@ function paramToDoc(
let type: DoctrineType = {
type: 'RestType'
};
if (param.typeAnnotation) {
type.expression = flowDoctrine(param.typeAnnotation.typeAnnotation);
}
return {
title: 'param',
name: prefix ? `${prefix}.${param.argument.name}` : param.argument.name,
Expand All @@ -214,11 +221,6 @@ function paramToDoc(
lineNumber: param.loc.start.line
};

// Flow/TS annotations
if (param.typeAnnotation && param.typeAnnotation.typeAnnotation) {
newParam.type = flowDoctrine(param.typeAnnotation.typeAnnotation);
}

return newParam;
}
}
Expand Down Expand Up @@ -277,7 +279,9 @@ function mergeTopNodes(inferred, explicit) {

var errors = explicitTagsWithoutInference.map(tag => {
return {
message: `An explicit parameter named ${tag.name || ''} was specified but didn't match ` +
message:
`An explicit parameter named ${tag.name ||
''} was specified but didn't match ` +
`inferred information ${Array.from(inferredNames).join(', ')}`,
commentLineNumber: tag.lineNumber
};
Expand Down

0 comments on commit 45c382a

Please sign in to comment.