From 794580103f581e6282edb7c0c4c9c0485001377d Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Fri, 3 May 2024 20:05:57 +1200 Subject: [PATCH] fix: special handling of identifiers no longer required --- src/utils/rule.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/utils/rule.ts b/src/utils/rule.ts index 8c04fb311..9b47a9746 100644 --- a/src/utils/rule.ts +++ b/src/utils/rule.ts @@ -14,6 +14,7 @@ import { type ImmutabilityOverrides, getTypeImmutability, } from "is-immutable-type"; +import { isIntrinsicErrorType } from "ts-api-utils"; import { type Node as TSNode, type Type, type TypeNode } from "typescript"; import ts from "#/conditional-imports/typescript"; @@ -262,14 +263,19 @@ export function getTypeImmutabilityOfNode< const overrides = explicitOverrides ?? getImmutabilityOverrides(context.settings); const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node); - const typedNode = ts.isIdentifier(tsNode) ? tsNode.parent : tsNode; - const typeLike = - (typedNode as { type?: TypeNode }).type ?? - getTypeOfNode(parserServices.tsNodeToESTreeNodeMap.get(typedNode), context); + let m_typeLike: Type | TypeNode | undefined = (tsNode as { type?: TypeNode }) + .type; + + if (m_typeLike === undefined) { + m_typeLike = getTypeOfTSNode(tsNode, context); + if (isIntrinsicErrorType(m_typeLike)) { + return Immutability.Unknown; + } + } return getTypeImmutability( parserServices.program, - typeLike, + m_typeLike, overrides, // Don't use the global cache in testing environments as it may cause errors when switching between different config options. process.env["NODE_ENV"] !== "test",