Skip to content

Commit

Permalink
Merge pull request #40985 from weswigham/static-decl-ref
Browse files Browse the repository at this point in the history
Adjust typeof import name lookup to better match type query lookup
  • Loading branch information
weswigham committed Oct 30, 2020
2 parents b9ed93e + 60b8bbc commit e044b56
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14415,7 +14415,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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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))

14 changes: 14 additions & 0 deletions tests/baselines/reference/importTypeTypeofClassStaticLookup.types
Original file line number Diff line number Diff line change
@@ -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

7 changes: 7 additions & 0 deletions tests/cases/compiler/importTypeTypeofClassStaticLookup.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit e044b56

Please sign in to comment.