Guard type-as-namespace property diagnostics during checker initialization

Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]andRyanCavanaugh authored and GitHub committed 2026-10-21 15:27:35 +00:00
1 parent 6bcf6ea635
commit 0946b9d3d7
5 files changed
+58 -1

No files matched your search

+1 -1
View File
@@ -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)
@@ -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.
@@ -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;
@@ -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))
@@ -0,0 +1,9 @@
//// [tests/cases/compiler/importEqualsTypeAsNamespaceNoLib.ts] ////
=== importEqualsTypeAsNamespaceNoLib.ts ===
interface C {}
import x = C.m;
>x : any
>C : any
>m : any