mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-26 19:25:41 -05:00
Handle all non-namespace types
This commit is contained in:
@@ -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)) {
|
||||
|
||||
@@ -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"]'?
|
||||
}
|
||||
}
|
||||
@@ -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 = {}));
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace Test1 {
|
||||
function foo<T extends { abc: number }>(x: T) {
|
||||
let a: T.abc = x.abc;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user