Skip to content

Adjust typeof import name lookup to better match type query lookup #40985

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
merged 2 commits into from
Oct 30, 2020
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
8 changes: 7 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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;