diff --git a/tsc/internal/checker/checker.go b/tsc/internal/checker/checker.go index 10ddb3c0c88b4..0e0c3902b687b 100644 --- a/tsc/internal/checker/checker.go +++ b/tsc/internal/checker/checker.go @@ -1677,7 +1677,7 @@ func (c *Checker) checkAndReportErrorForUsingTypeAsNamespace(errorLocation *ast. symbol := c.resolveSymbol(c.resolveName(errorLocation, name, ast.SymbolFlagsType&^ast.SymbolFlagsNamespace, nil /*nameNotFoundMessage*/, false /*isUse*/, false /*excludeGlobals*/)) if symbol != nil { parent := errorLocation.Parent - if ast.IsQualifiedName(parent) { + if c.globalObjectType != nil && ast.IsQualifiedName(parent) { debug.Assert(parent.AsQualifiedName().Left == errorLocation, "Should only be resolving left side of qualified name as a namespace") propName := parent.AsQualifiedName().Right.Text() propType := c.getPropertyOfType(c.getDeclaredTypeOfSymbol(symbol), propName) diff --git a/tsc/testdata/baselines/reference/compiler/importEqualsTypeAsNamespaceNoLib.errors.txt b/tsc/testdata/baselines/reference/compiler/importEqualsTypeAsNamespaceNoLib.errors.txt new file mode 100644 index 0000000000000..a4e1c22e06527 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/importEqualsTypeAsNamespaceNoLib.errors.txt @@ -0,0 +1,29 @@ +error TS2318: Cannot find global type 'Array'. +error TS2318: Cannot find global type 'Boolean'. +error TS2318: Cannot find global type 'CallableFunction'. +error TS2318: Cannot find global type 'Function'. +error TS2318: Cannot find global type 'IArguments'. +error TS2318: Cannot find global type 'NewableFunction'. +error TS2318: Cannot find global type 'Number'. +error TS2318: Cannot find global type 'Object'. +error TS2318: Cannot find global type 'RegExp'. +error TS2318: Cannot find global type 'String'. +importEqualsTypeAsNamespaceNoLib.ts(2,12): error TS2702: 'C' only refers to a type, but is being used as a namespace here. + + +!!! error TS2318: Cannot find global type 'Array'. +!!! error TS2318: Cannot find global type 'Boolean'. +!!! error TS2318: Cannot find global type 'CallableFunction'. +!!! error TS2318: Cannot find global type 'Function'. +!!! error TS2318: Cannot find global type 'IArguments'. +!!! error TS2318: Cannot find global type 'NewableFunction'. +!!! error TS2318: Cannot find global type 'Number'. +!!! error TS2318: Cannot find global type 'Object'. +!!! error TS2318: Cannot find global type 'RegExp'. +!!! error TS2318: Cannot find global type 'String'. +==== importEqualsTypeAsNamespaceNoLib.ts (1 errors) ==== + interface C {} + import x = C.m; + ~ +!!! error TS2702: 'C' only refers to a type, but is being used as a namespace here. + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/importEqualsTypeAsNamespaceNoLib.js b/tsc/testdata/baselines/reference/compiler/importEqualsTypeAsNamespaceNoLib.js new file mode 100644 index 0000000000000..96d709e3fa78d --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/importEqualsTypeAsNamespaceNoLib.js @@ -0,0 +1,10 @@ +//// [tests/cases/compiler/importEqualsTypeAsNamespaceNoLib.ts] //// + +//// [importEqualsTypeAsNamespaceNoLib.ts] +interface C {} +import x = C.m; + + +//// [importEqualsTypeAsNamespaceNoLib.js] +"use strict"; +var x = C.m; diff --git a/tsc/testdata/baselines/reference/compiler/importEqualsTypeAsNamespaceNoLib.symbols b/tsc/testdata/baselines/reference/compiler/importEqualsTypeAsNamespaceNoLib.symbols new file mode 100644 index 0000000000000..c227c74b2fdc1 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/importEqualsTypeAsNamespaceNoLib.symbols @@ -0,0 +1,9 @@ +//// [tests/cases/compiler/importEqualsTypeAsNamespaceNoLib.ts] //// + +=== importEqualsTypeAsNamespaceNoLib.ts === +interface C {} +>C : Symbol(C, Decl(importEqualsTypeAsNamespaceNoLib.ts, 0, 0)) + +import x = C.m; +>x : Symbol(x, Decl(importEqualsTypeAsNamespaceNoLib.ts, 0, 14)) + diff --git a/tsc/testdata/baselines/reference/compiler/importEqualsTypeAsNamespaceNoLib.types b/tsc/testdata/baselines/reference/compiler/importEqualsTypeAsNamespaceNoLib.types new file mode 100644 index 0000000000000..5c278d735819a --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/importEqualsTypeAsNamespaceNoLib.types @@ -0,0 +1,9 @@ +//// [tests/cases/compiler/importEqualsTypeAsNamespaceNoLib.ts] //// + +=== importEqualsTypeAsNamespaceNoLib.ts === +interface C {} +import x = C.m; +>x : any +>C : any +>m : any + diff --git a/tsc/testdata/tests/cases/compiler/importEqualsTypeAsNamespaceNoLib.ts b/tsc/testdata/tests/cases/compiler/importEqualsTypeAsNamespaceNoLib.ts new file mode 100644 index 0000000000000..7a69475bbdcaf --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/importEqualsTypeAsNamespaceNoLib.ts @@ -0,0 +1,4 @@ +// @noLib: true + +interface C {} +import x = C.m;