diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d328ed25f5489..ca8d6c98a4b13 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14346,7 +14346,13 @@ namespace ts { let current: Identifier | undefined; while (current = nameStack.shift()) { const meaning = nameStack.length ? SymbolFlags.Namespace : targetMeaning; - const next = getSymbol(getExportsOfSymbol(getMergedSymbol(resolveSymbol(currentNamespace))), current.escapedText, meaning); + // typeof a.b.c is normally resolved using `checkExpression` which in turn defers to `checkQualifiedName` + // That, in turn, ultimately uses `getPropertyOfType` on the type of the symbol, which differs slightly from + // the `exports` lookup process that only looks up namespace members which is used for most type references + const mergedResolvedSymbol = getMergedSymbol(resolveSymbol(currentNamespace)); + const next = node.isTypeOf + ? getPropertyOfType(getTypeOfSymbol(mergedResolvedSymbol), current.escapedText) + : getSymbol(getExportsOfSymbol(mergedResolvedSymbol), current.escapedText, meaning); if (!next) { error(current, Diagnostics.Namespace_0_has_no_exported_member_1, getFullyQualifiedName(currentNamespace), declarationNameToString(current)); return links.resolvedType = errorType; diff --git a/tests/baselines/reference/importTypeTypeofClassStaticLookup.symbols b/tests/baselines/reference/importTypeTypeofClassStaticLookup.symbols new file mode 100644 index 0000000000000..897bc83259c07 --- /dev/null +++ b/tests/baselines/reference/importTypeTypeofClassStaticLookup.symbols @@ -0,0 +1,14 @@ +=== tests/cases/compiler/a.d.ts === +export declare class A { +>A : Symbol(A, Decl(a.d.ts, 0, 0)) + + static foo(): void; +>foo : Symbol(A.foo, Decl(a.d.ts, 0, 24)) +} + +=== tests/cases/compiler/index.d.ts === +export const foo: typeof import("./a").A.foo; +>foo : Symbol(foo, Decl(index.d.ts, 0, 12)) +>A : Symbol(A, Decl(a.d.ts, 0, 0)) +>foo : Symbol(A.foo, Decl(a.d.ts, 0, 24)) + diff --git a/tests/baselines/reference/importTypeTypeofClassStaticLookup.types b/tests/baselines/reference/importTypeTypeofClassStaticLookup.types new file mode 100644 index 0000000000000..2a39e1bc9840c --- /dev/null +++ b/tests/baselines/reference/importTypeTypeofClassStaticLookup.types @@ -0,0 +1,14 @@ +=== tests/cases/compiler/a.d.ts === +export declare class A { +>A : A + + static foo(): void; +>foo : () => void +} + +=== tests/cases/compiler/index.d.ts === +export const foo: typeof import("./a").A.foo; +>foo : () => void +>A : any +>foo : any + diff --git a/tests/cases/compiler/importTypeTypeofClassStaticLookup.ts b/tests/cases/compiler/importTypeTypeofClassStaticLookup.ts new file mode 100644 index 0000000000000..841624f47a8be --- /dev/null +++ b/tests/cases/compiler/importTypeTypeofClassStaticLookup.ts @@ -0,0 +1,7 @@ +// @filename: a.d.ts +export declare class A { + static foo(): void; +} + +// @filename: index.d.ts +export const foo: typeof import("./a").A.foo; \ No newline at end of file