Skip to content

Commit e044b56

Browse files
authored
Merge pull request microsoft#40985 from weswigham/static-decl-ref
Adjust typeof import name lookup to better match type query lookup
2 parents b9ed93e + 60b8bbc commit e044b56

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14415,7 +14415,13 @@ namespace ts {
1441514415
let current: Identifier | undefined;
1441614416
while (current = nameStack.shift()) {
1441714417
const meaning = nameStack.length ? SymbolFlags.Namespace : targetMeaning;
14418-
const next = getSymbol(getExportsOfSymbol(getMergedSymbol(resolveSymbol(currentNamespace))), current.escapedText, meaning);
14418+
// typeof a.b.c is normally resolved using `checkExpression` which in turn defers to `checkQualifiedName`
14419+
// That, in turn, ultimately uses `getPropertyOfType` on the type of the symbol, which differs slightly from
14420+
// the `exports` lookup process that only looks up namespace members which is used for most type references
14421+
const mergedResolvedSymbol = getMergedSymbol(resolveSymbol(currentNamespace));
14422+
const next = node.isTypeOf
14423+
? getPropertyOfType(getTypeOfSymbol(mergedResolvedSymbol), current.escapedText)
14424+
: getSymbol(getExportsOfSymbol(mergedResolvedSymbol), current.escapedText, meaning);
1441914425
if (!next) {
1442014426
error(current, Diagnostics.Namespace_0_has_no_exported_member_1, getFullyQualifiedName(currentNamespace), declarationNameToString(current));
1442114427
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)