From dd10c3fc709feccc9acd642ad16795dd86c78fa2 Mon Sep 17 00:00:00 2001 From: Ting-Hsiang Hsu Date: Thu, 13 Jun 2019 22:11:54 +0800 Subject: [PATCH] fix: fix error with other cases (#412) --- src/rules/useFlowType.js | 8 +++++++- tests/rules/assertions/useFlowType.js | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/rules/useFlowType.js b/src/rules/useFlowType.js index dba4d23d..cb612f58 100644 --- a/src/rules/useFlowType.js +++ b/src/rules/useFlowType.js @@ -36,8 +36,14 @@ const create = (context) => { TypeParameterDeclaration (node) { node.params.forEach((param) => { if (param.default && param.default.typeParameters) { + if (param.default.type === 'GenericTypeAnnotation') { + markTypeAsUsedWithGenericType(param.default); + } + param.default.typeParameters.params.forEach((typeParameterNode) => { - markTypeAsUsedWithGenericType(typeParameterNode); + if (typeParameterNode.type === 'GenericTypeAnnotation') { + markTypeAsUsedWithGenericType(typeParameterNode); + } }); } }); diff --git a/tests/rules/assertions/useFlowType.js b/tests/rules/assertions/useFlowType.js index 526b91c5..b002ad35 100644 --- a/tests/rules/assertions/useFlowType.js +++ b/tests/rules/assertions/useFlowType.js @@ -40,6 +40,12 @@ const VALID_WITH_USE_FLOW_TYPE = [ errors: [ '\'A\' is defined but never used.' ] + }, + { + code: 'import type A from "a"; type X> = { b: B }; let x: X; console.log(x);', + errors: [ + '\'A\' is defined but never used.' + ] } ];