Skip to content

Commit c6734af

Browse files
committed
Adjust typeof import name lookup to better match type query lookup
1 parent 692502e commit c6734af

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14346,7 +14346,10 @@ namespace ts {
1434614346
let current: Identifier | undefined;
1434714347
while (current = nameStack.shift()) {
1434814348
const meaning = nameStack.length ? SymbolFlags.Namespace : targetMeaning;
14349-
const next = getSymbol(getExportsOfSymbol(getMergedSymbol(resolveSymbol(currentNamespace))), current.escapedText, meaning);
14349+
// typeof a.b.c is normally resolved using `checkExpression` which in turn defers to `checkQualifiedName`
14350+
// That, in turn, ultimately uses `getPropertyOfType` on the type of the symbol, which differs slightly from
14351+
// the `exports` lookup process that only looks up namespace members which is used for most type references
14352+
const next = node.isTypeOf ? getPropertyOfType(getTypeOfSymbol(resolveSymbol(currentNamespace)), current.escapedText) : getSymbol(getExportsOfSymbol(getMergedSymbol(resolveSymbol(currentNamespace))), current.escapedText, meaning);
1435014353
if (!next) {
1435114354
error(current, Diagnostics.Namespace_0_has_no_exported_member_1, getFullyQualifiedName(currentNamespace), declarationNameToString(current));
1435214355
return links.resolvedType = errorType;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/compiler/a.d.ts ===
2+
export declare class A {
3+
>A : Symbol(A, Decl(a.d.ts, 0, 0))
4+
5+
static foo(): void;
6+
>foo : Symbol(A.foo, Decl(a.d.ts, 0, 24))
7+
}
8+
9+
=== tests/cases/compiler/index.d.ts ===
10+
export const foo: typeof import("./a").A.foo;
11+
>foo : Symbol(foo, Decl(index.d.ts, 0, 12))
12+
>A : Symbol(A, Decl(a.d.ts, 0, 0))
13+
>foo : Symbol(A.foo, Decl(a.d.ts, 0, 24))
14+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/compiler/a.d.ts ===
2+
export declare class A {
3+
>A : A
4+
5+
static foo(): void;
6+
>foo : () => void
7+
}
8+
9+
=== tests/cases/compiler/index.d.ts ===
10+
export const foo: typeof import("./a").A.foo;
11+
>foo : () => void
12+
>A : any
13+
>foo : any
14+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @filename: a.d.ts
2+
export declare class A {
3+
static foo(): void;
4+
}
5+
6+
// @filename: index.d.ts
7+
export const foo: typeof import("./a").A.foo;

0 commit comments

Comments
 (0)