Adjust typeof import name lookup to better match type query lookup

This commit is contained in:
Wesley Wigham 2020-10-07 12:08:20 -07:00
parent 692502e99f
commit c6734afba5
No known key found for this signature in database
GPG key ID: D59F87F60C5400C9
4 changed files with 39 additions and 1 deletions

View file

@ -14346,7 +14346,10 @@ 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 next = node.isTypeOf ? getPropertyOfType(getTypeOfSymbol(resolveSymbol(currentNamespace)), current.escapedText) : getSymbol(getExportsOfSymbol(getMergedSymbol(resolveSymbol(currentNamespace))), current.escapedText, meaning);
if (!next) {
error(current, Diagnostics.Namespace_0_has_no_exported_member_1, getFullyQualifiedName(currentNamespace), declarationNameToString(current));
return links.resolvedType = errorType;

View file

@ -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))

View file

@ -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

View file

@ -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;