From 3dcc064303830783529bb689abc4b49e959a6a92 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Wed, 29 Nov 2017 11:32:45 -0800 Subject: [PATCH] Apply TS2713 to classes Formerly, they were excluded as values, but the error is just as relevant for classes. Note that it is not applied to enums since switching to an indexed access expression will not help for an enum. --- src/compiler/checker.ts | 2 +- ...MetadataWithImportDeclarationNameCollision7.errors.txt | 8 ++++---- .../errorForUsingPropertyOfTypeAsType01.errors.txt | 6 +++--- .../reference/invalidImportAliasIdentifiers.errors.txt | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ffb2b673210..c671a3f7fd2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1338,7 +1338,7 @@ namespace ts { function checkAndReportErrorForUsingTypeAsNamespace(errorLocation: Node, name: __String, meaning: SymbolFlags): boolean { if (meaning === SymbolFlags.Namespace) { - const symbol = resolveSymbol(resolveName(errorLocation, name, SymbolFlags.Type & ~SymbolFlags.Value, /*nameNotFoundMessage*/undefined, /*nameArg*/ undefined, /*isUse*/ false)); + const symbol = resolveSymbol(resolveName(errorLocation, name, SymbolFlags.Class | SymbolFlags.Interface | SymbolFlags.TypeAlias, /*nameNotFoundMessage*/undefined, /*nameArg*/ undefined, /*isUse*/ false)); const parent = errorLocation.parent; if (symbol) { if (isQualifiedName(parent)) { diff --git a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision7.errors.txt b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision7.errors.txt index d4b714f1d4a..9fba625f3ad 100644 --- a/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision7.errors.txt +++ b/tests/baselines/reference/decoratorMetadataWithImportDeclarationNameCollision7.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/service.ts(7,9): error TS2503: Cannot find namespace 'db'. -tests/cases/compiler/service.ts(9,21): error TS2503: Cannot find namespace 'db'. +tests/cases/compiler/service.ts(7,9): error TS2702: 'db' only refers to a type, but is being used as a namespace here. +tests/cases/compiler/service.ts(9,21): error TS2702: 'db' only refers to a type, but is being used as a namespace here. ==== tests/cases/compiler/db.ts (0 errors) ==== @@ -17,11 +17,11 @@ tests/cases/compiler/service.ts(9,21): error TS2503: Cannot find namespace 'db'. class MyClass { db: db.db; //error ~~ -!!! error TS2503: Cannot find namespace 'db'. +!!! error TS2702: 'db' only refers to a type, but is being used as a namespace here. constructor(db: db.db) { // error ~~ -!!! error TS2503: Cannot find namespace 'db'. +!!! error TS2702: 'db' only refers to a type, but is being used as a namespace here. this.db = db; this.db.doSomething(); } diff --git a/tests/baselines/reference/errorForUsingPropertyOfTypeAsType01.errors.txt b/tests/baselines/reference/errorForUsingPropertyOfTypeAsType01.errors.txt index 0c55ba75f13..58f9f2cc6d4 100644 --- a/tests/baselines/reference/errorForUsingPropertyOfTypeAsType01.errors.txt +++ b/tests/baselines/reference/errorForUsingPropertyOfTypeAsType01.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/errorForUsingPropertyOfTypeAsType01.ts(6,12): error TS2713: Cannot access 'Foo.bar' because 'Foo' is a type, but not a namespace. Did you mean to retrieve the type of the property 'bar' in 'Foo' with 'Foo["bar"]'? tests/cases/compiler/errorForUsingPropertyOfTypeAsType01.ts(7,18): error TS2694: Namespace 'Test1' has no exported member 'Foo'. -tests/cases/compiler/errorForUsingPropertyOfTypeAsType01.ts(15,12): error TS2503: Cannot find namespace 'Foo'. +tests/cases/compiler/errorForUsingPropertyOfTypeAsType01.ts(15,12): error TS2713: Cannot access 'Foo.bar' because 'Foo' is a type, but not a namespace. Did you mean to retrieve the type of the property 'bar' in 'Foo' with 'Foo["bar"]'? tests/cases/compiler/errorForUsingPropertyOfTypeAsType01.ts(16,18): error TS2694: Namespace 'Test2' has no exported member 'Foo'. tests/cases/compiler/errorForUsingPropertyOfTypeAsType01.ts(24,12): error TS2713: Cannot access 'Foo.bar' because 'Foo' is a type, but not a namespace. Did you mean to retrieve the type of the property 'bar' in 'Foo' with 'Foo["bar"]'? tests/cases/compiler/errorForUsingPropertyOfTypeAsType01.ts(25,18): error TS2694: Namespace 'Test3' has no exported member 'Foo'. @@ -32,8 +32,8 @@ tests/cases/compiler/errorForUsingPropertyOfTypeAsType01.ts(44,24): error TS1003 } var x: Foo.bar = ""; - ~~~ -!!! error TS2503: Cannot find namespace 'Foo'. + ~~~~~~~ +!!! error TS2713: Cannot access 'Foo.bar' because 'Foo' is a type, but not a namespace. Did you mean to retrieve the type of the property 'bar' in 'Foo' with 'Foo["bar"]'? var y: Test2.Foo.bar = ""; ~~~ !!! error TS2694: Namespace 'Test2' has no exported member 'Foo'. diff --git a/tests/baselines/reference/invalidImportAliasIdentifiers.errors.txt b/tests/baselines/reference/invalidImportAliasIdentifiers.errors.txt index c69cc85ad9d..570b41f499d 100644 --- a/tests/baselines/reference/invalidImportAliasIdentifiers.errors.txt +++ b/tests/baselines/reference/invalidImportAliasIdentifiers.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(5,12): error TS2503: Cannot find namespace 'V'. -tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(11,12): error TS2503: Cannot find namespace 'C'. +tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(11,12): error TS2702: 'C' only refers to a type, but is being used as a namespace here. tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(23,12): error TS2702: 'I' only refers to a type, but is being used as a namespace here. @@ -18,7 +18,7 @@ tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIde import c = C; ~ -!!! error TS2503: Cannot find namespace 'C'. +!!! error TS2702: 'C' only refers to a type, but is being used as a namespace here. enum E { Red, Blue