Handle all non-namespace types

This commit is contained in:
Andrew Casey
2017-11-29 15:49:58 -08:00
parent 3dcc064303
commit 31c4ca5235
6 changed files with 69 additions and 1 deletions

View File

@@ -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.Class | SymbolFlags.Interface | SymbolFlags.TypeAlias, /*nameNotFoundMessage*/undefined, /*nameArg*/ undefined, /*isUse*/ false));
const symbol = resolveSymbol(resolveName(errorLocation, name, SymbolFlags.Type & ~SymbolFlags.Namespace, /*nameNotFoundMessage*/undefined, /*nameArg*/ undefined, /*isUse*/ false));
const parent = errorLocation.parent;
if (symbol) {
if (isQualifiedName(parent)) {

View File

@@ -0,0 +1,11 @@
tests/cases/compiler/errorForUsingPropertyOfTypeAsType02.ts(3,16): error TS2713: Cannot access 'T.abc' because 'T' is a type, but not a namespace. Did you mean to retrieve the type of the property 'abc' in 'T' with 'T["abc"]'?
==== tests/cases/compiler/errorForUsingPropertyOfTypeAsType02.ts (1 errors) ====
namespace Test1 {
function foo<T extends { abc: number }>(x: T) {
let a: T.abc = x.abc;
~~~~~
!!! error TS2713: Cannot access 'T.abc' because 'T' is a type, but not a namespace. Did you mean to retrieve the type of the property 'abc' in 'T' with 'T["abc"]'?
}
}

View File

@@ -0,0 +1,14 @@
//// [errorForUsingPropertyOfTypeAsType02.ts]
namespace Test1 {
function foo<T extends { abc: number }>(x: T) {
let a: T.abc = x.abc;
}
}
//// [errorForUsingPropertyOfTypeAsType02.js]
var Test1;
(function (Test1) {
function foo(x) {
var a = x.abc;
}
})(Test1 || (Test1 = {}));

View File

@@ -0,0 +1,18 @@
=== tests/cases/compiler/errorForUsingPropertyOfTypeAsType02.ts ===
namespace Test1 {
>Test1 : Symbol(Test1, Decl(errorForUsingPropertyOfTypeAsType02.ts, 0, 0))
function foo<T extends { abc: number }>(x: T) {
>foo : Symbol(foo, Decl(errorForUsingPropertyOfTypeAsType02.ts, 0, 17))
>T : Symbol(T, Decl(errorForUsingPropertyOfTypeAsType02.ts, 1, 17))
>abc : Symbol(abc, Decl(errorForUsingPropertyOfTypeAsType02.ts, 1, 28))
>x : Symbol(x, Decl(errorForUsingPropertyOfTypeAsType02.ts, 1, 44))
>T : Symbol(T, Decl(errorForUsingPropertyOfTypeAsType02.ts, 1, 17))
let a: T.abc = x.abc;
>a : Symbol(a, Decl(errorForUsingPropertyOfTypeAsType02.ts, 2, 11))
>x.abc : Symbol(abc, Decl(errorForUsingPropertyOfTypeAsType02.ts, 1, 28))
>x : Symbol(x, Decl(errorForUsingPropertyOfTypeAsType02.ts, 1, 44))
>abc : Symbol(abc, Decl(errorForUsingPropertyOfTypeAsType02.ts, 1, 28))
}
}

View File

@@ -0,0 +1,20 @@
=== tests/cases/compiler/errorForUsingPropertyOfTypeAsType02.ts ===
namespace Test1 {
>Test1 : typeof Test1
function foo<T extends { abc: number }>(x: T) {
>foo : <T extends { abc: number; }>(x: T) => void
>T : T
>abc : number
>x : T
>T : T
let a: T.abc = x.abc;
>a : any
>T : any
>abc : No type information available!
>x.abc : number
>x : T
>abc : number
}
}

View File

@@ -0,0 +1,5 @@
namespace Test1 {
function foo<T extends { abc: number }>(x: T) {
let a: T.abc = x.abc;
}
}