From 31c4ca52355d4c3cadb6d097f0df1fa709cf58bf Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Wed, 29 Nov 2017 15:49:58 -0800 Subject: [PATCH] Handle all non-namespace types --- src/compiler/checker.ts | 2 +- ...rForUsingPropertyOfTypeAsType02.errors.txt | 11 ++++++++++ .../errorForUsingPropertyOfTypeAsType02.js | 14 +++++++++++++ ...rrorForUsingPropertyOfTypeAsType02.symbols | 18 +++++++++++++++++ .../errorForUsingPropertyOfTypeAsType02.types | 20 +++++++++++++++++++ .../errorForUsingPropertyOfTypeAsType02.ts | 5 +++++ 6 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/errorForUsingPropertyOfTypeAsType02.errors.txt create mode 100644 tests/baselines/reference/errorForUsingPropertyOfTypeAsType02.js create mode 100644 tests/baselines/reference/errorForUsingPropertyOfTypeAsType02.symbols create mode 100644 tests/baselines/reference/errorForUsingPropertyOfTypeAsType02.types create mode 100644 tests/cases/compiler/errorForUsingPropertyOfTypeAsType02.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c671a3f7fd2..8d7662bc99c 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.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)) { diff --git a/tests/baselines/reference/errorForUsingPropertyOfTypeAsType02.errors.txt b/tests/baselines/reference/errorForUsingPropertyOfTypeAsType02.errors.txt new file mode 100644 index 00000000000..53831fb54af --- /dev/null +++ b/tests/baselines/reference/errorForUsingPropertyOfTypeAsType02.errors.txt @@ -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(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"]'? + } + } \ No newline at end of file diff --git a/tests/baselines/reference/errorForUsingPropertyOfTypeAsType02.js b/tests/baselines/reference/errorForUsingPropertyOfTypeAsType02.js new file mode 100644 index 00000000000..d621a89cbf2 --- /dev/null +++ b/tests/baselines/reference/errorForUsingPropertyOfTypeAsType02.js @@ -0,0 +1,14 @@ +//// [errorForUsingPropertyOfTypeAsType02.ts] +namespace Test1 { + function foo(x: T) { + let a: T.abc = x.abc; + } +} + +//// [errorForUsingPropertyOfTypeAsType02.js] +var Test1; +(function (Test1) { + function foo(x) { + var a = x.abc; + } +})(Test1 || (Test1 = {})); diff --git a/tests/baselines/reference/errorForUsingPropertyOfTypeAsType02.symbols b/tests/baselines/reference/errorForUsingPropertyOfTypeAsType02.symbols new file mode 100644 index 00000000000..b96d18c1981 --- /dev/null +++ b/tests/baselines/reference/errorForUsingPropertyOfTypeAsType02.symbols @@ -0,0 +1,18 @@ +=== tests/cases/compiler/errorForUsingPropertyOfTypeAsType02.ts === +namespace Test1 { +>Test1 : Symbol(Test1, Decl(errorForUsingPropertyOfTypeAsType02.ts, 0, 0)) + + function foo(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)) + } +} diff --git a/tests/baselines/reference/errorForUsingPropertyOfTypeAsType02.types b/tests/baselines/reference/errorForUsingPropertyOfTypeAsType02.types new file mode 100644 index 00000000000..11097df6cc7 --- /dev/null +++ b/tests/baselines/reference/errorForUsingPropertyOfTypeAsType02.types @@ -0,0 +1,20 @@ +=== tests/cases/compiler/errorForUsingPropertyOfTypeAsType02.ts === +namespace Test1 { +>Test1 : typeof Test1 + + function foo(x: T) { +>foo : (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 + } +} diff --git a/tests/cases/compiler/errorForUsingPropertyOfTypeAsType02.ts b/tests/cases/compiler/errorForUsingPropertyOfTypeAsType02.ts new file mode 100644 index 00000000000..459debe63a5 --- /dev/null +++ b/tests/cases/compiler/errorForUsingPropertyOfTypeAsType02.ts @@ -0,0 +1,5 @@ +namespace Test1 { + function foo(x: T) { + let a: T.abc = x.abc; + } +} \ No newline at end of file