Skip to content

Commit

Permalink
fix: check contextual type too to avoid false positive
Browse files Browse the repository at this point in the history
  • Loading branch information
plantain-00 committed Jun 28, 2020
1 parent dd21dcb commit 93399ff
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/core/src/checker.ts
Expand Up @@ -28,10 +28,19 @@ function collectNotAny(node: ts.Node, { file, sourceFile, typeCheckResult, debug
}

function collectData(node: ts.Node, context: FileContext) {
const types: ts.Type[] = []
const type = context.checker.getTypeAtLocation(node)
if (type) {
types.push(type)
}
const contextualType = context.checker.getContextualType(node as ts.Expression)
if (contextualType) {
types.push(contextualType)
}

if (types.length > 0) {
context.typeCheckResult.totalCount++
if (typeIsStrictAny(type, context.strict)) {
if (types.every((t) => typeIsStrictAny(t, context.strict))) {
const success = collectAny(node, context)
if (!success) {
collectNotAny(node, context, type)
Expand Down

0 comments on commit 93399ff

Please sign in to comment.