From f3cc639346806c0956f93e6a848847f73e77f4ae Mon Sep 17 00:00:00 2001 From: Renegade334 Date: Mon, 7 Jul 2025 14:21:57 +0100 Subject: [PATCH] fix(type-utils): handle namespaced exports in specifier matching --- .../typeDeclaredInPackageDeclarationFile.ts | 7 +++++-- packages/type-utils/tests/TypeOrValueSpecifier.test.ts | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/type-utils/src/typeOrValueSpecifiers/typeDeclaredInPackageDeclarationFile.ts b/packages/type-utils/src/typeOrValueSpecifiers/typeDeclaredInPackageDeclarationFile.ts index cb0b303bafac..e0da69700a83 100644 --- a/packages/type-utils/src/typeOrValueSpecifiers/typeDeclaredInPackageDeclarationFile.ts +++ b/packages/type-utils/src/typeOrValueSpecifiers/typeDeclaredInPackageDeclarationFile.ts @@ -5,14 +5,17 @@ function findParentModuleDeclaration( ): ts.ModuleDeclaration | undefined { switch (node.kind) { case ts.SyntaxKind.ModuleDeclaration: + // "namespace x {...}" should be ignored here + if (node.flags & ts.NodeFlags.Namespace) { + break; + } return ts.isStringLiteral((node as ts.ModuleDeclaration).name) ? (node as ts.ModuleDeclaration) : undefined; case ts.SyntaxKind.SourceFile: return undefined; - default: - return findParentModuleDeclaration(node.parent); } + return findParentModuleDeclaration(node.parent); } function typeDeclaredInDeclareModule( diff --git a/packages/type-utils/tests/TypeOrValueSpecifier.test.ts b/packages/type-utils/tests/TypeOrValueSpecifier.test.ts index 8aee949efb37..86806ad1dae2 100644 --- a/packages/type-utils/tests/TypeOrValueSpecifier.test.ts +++ b/packages/type-utils/tests/TypeOrValueSpecifier.test.ts @@ -405,6 +405,14 @@ describe('TypeOrValueSpecifier', () => { package: 'node:test', }, ], + [ + 'import { fail } from "node:assert"; type Test = typeof fail;', + { + from: 'package', + name: 'fail', + package: 'assert', + }, + ], ] as const satisfies [string, TypeOrValueSpecifier][])( 'matches a matching package specifier: %s\n\t%s', ([code, typeOrValueSpecifier], { expect }) => { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy