Skip to content

fix(type-utils): handle namespaced exports in specifier matching #11380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 8 additions & 0 deletions packages/type-utils/tests/TypeOrValueSpecifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down