Merge pull request #10333 from jwbay/better-type-as-value-error

Add clearer error message when types are used as values
This commit is contained in:
Mohamed Hegazy 2016-09-13 14:15:48 -07:00 committed by GitHub
commit e6479334e1
30 changed files with 284 additions and 69 deletions

View File

@ -877,7 +877,8 @@ namespace ts {
if (nameNotFoundMessage) {
if (!errorLocation ||
!checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) &&
!checkAndReportErrorForExtendingInterface(errorLocation)) {
!checkAndReportErrorForExtendingInterface(errorLocation) &&
!checkAndReportErrorForUsingTypeAsValue(errorLocation, name, meaning)) {
error(errorLocation, nameNotFoundMessage, typeof nameArg === "string" ? nameArg : declarationNameToString(nameArg));
}
}
@ -987,6 +988,16 @@ namespace ts {
}
}
function checkAndReportErrorForUsingTypeAsValue(errorLocation: Node, name: string, meaning: SymbolFlags): boolean {
if (meaning & (SymbolFlags.Value & ~SymbolFlags.NamespaceModule)) {
const symbol = resolveSymbol(resolveName(errorLocation, name, SymbolFlags.Type & ~SymbolFlags.Value, /*nameNotFoundMessage*/undefined, /*nameArg*/ undefined));
if (symbol && !(symbol.flags & SymbolFlags.NamespaceModule)) {
error(errorLocation, Diagnostics._0_only_refers_to_a_type_but_is_being_used_as_a_value_here, name);
return true;
}
}
return false;
}
function checkResolvedBlockScopedVariable(result: Symbol, errorLocation: Node): void {
Debug.assert((result.flags & SymbolFlags.BlockScopedVariable) !== 0);

View File

@ -1947,6 +1947,10 @@
"category": "Error",
"code": 2692
},
"'{0}' only refers to a type, but is being used as a value here.": {
"category": "Error",
"code": 2693
},
"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
"code": 4000

View File

@ -3,7 +3,7 @@ tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(14,1): er
tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(17,1): error TS2364: Invalid left-hand side of assignment expression.
tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(18,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property.
tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(21,1): error TS2364: Invalid left-hand side of assignment expression.
tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(31,1): error TS2304: Cannot find name 'I'.
tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(31,1): error TS2693: 'I' only refers to a type, but is being used as a value here.
==== tests/cases/conformance/expressions/valuesAndReferences/assignments.ts (6 errors) ====
@ -49,4 +49,4 @@ tests/cases/conformance/expressions/valuesAndReferences/assignments.ts(31,1): er
interface I { }
I = null; // Error
~
!!! error TS2304: Cannot find name 'I'.
!!! error TS2693: 'I' only refers to a type, but is being used as a value here.

View File

@ -1,4 +1,4 @@
tests/cases/compiler/classExtendsInterfaceInExpression.ts(7,25): error TS2304: Cannot find name 'A'.
tests/cases/compiler/classExtendsInterfaceInExpression.ts(7,25): error TS2693: 'A' only refers to a type, but is being used as a value here.
==== tests/cases/compiler/classExtendsInterfaceInExpression.ts (1 errors) ====
@ -10,5 +10,5 @@ tests/cases/compiler/classExtendsInterfaceInExpression.ts(7,25): error TS2304: C
class C extends factory(A) {}
~
!!! error TS2304: Cannot find name 'A'.
!!! error TS2693: 'A' only refers to a type, but is being used as a value here.

View File

@ -1,15 +1,15 @@
tests/cases/compiler/errorsOnImportedSymbol_1.ts(2,13): error TS2304: Cannot find name 'Sammy'.
tests/cases/compiler/errorsOnImportedSymbol_1.ts(3,9): error TS2304: Cannot find name 'Sammy'.
tests/cases/compiler/errorsOnImportedSymbol_1.ts(2,13): error TS2693: 'Sammy' only refers to a type, but is being used as a value here.
tests/cases/compiler/errorsOnImportedSymbol_1.ts(3,9): error TS2693: 'Sammy' only refers to a type, but is being used as a value here.
==== tests/cases/compiler/errorsOnImportedSymbol_1.ts (2 errors) ====
import Sammy = require("./errorsOnImportedSymbol_0");
var x = new Sammy.Sammy();
~~~~~
!!! error TS2304: Cannot find name 'Sammy'.
!!! error TS2693: 'Sammy' only refers to a type, but is being used as a value here.
var y = Sammy.Sammy();
~~~~~
!!! error TS2304: Cannot find name 'Sammy'.
!!! error TS2693: 'Sammy' only refers to a type, but is being used as a value here.
==== tests/cases/compiler/errorsOnImportedSymbol_0.ts (0 errors) ====

View File

@ -1,4 +1,4 @@
tests/cases/compiler/main.ts(15,1): error TS2304: Cannot find name 'z1'.
tests/cases/compiler/main.ts(15,1): error TS2693: 'z1' only refers to a type, but is being used as a value here.
tests/cases/compiler/main.ts(21,4): error TS2339: Property 'a' does not exist on type '() => any'.
tests/cases/compiler/main.ts(23,4): error TS2339: Property 'a' does not exist on type 'typeof Foo'.
tests/cases/compiler/main.ts(27,8): error TS1192: Module '"interface"' has no default export.
@ -49,7 +49,7 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses
z1.a;
~~
!!! error TS2304: Cannot find name 'z1'.
!!! error TS2693: 'z1' only refers to a type, but is being used as a value here.
z2.a;
z3.a;
z4.a;

View File

@ -1,5 +1,5 @@
tests/cases/compiler/exportAssignmentOfDeclaredExternalModule_1.ts(3,13): error TS2304: Cannot find name 'Sammy'.
tests/cases/compiler/exportAssignmentOfDeclaredExternalModule_1.ts(4,9): error TS2304: Cannot find name 'Sammy'.
tests/cases/compiler/exportAssignmentOfDeclaredExternalModule_1.ts(3,13): error TS2693: 'Sammy' only refers to a type, but is being used as a value here.
tests/cases/compiler/exportAssignmentOfDeclaredExternalModule_1.ts(4,9): error TS2693: 'Sammy' only refers to a type, but is being used as a value here.
==== tests/cases/compiler/exportAssignmentOfDeclaredExternalModule_1.ts (2 errors) ====
@ -7,10 +7,10 @@ tests/cases/compiler/exportAssignmentOfDeclaredExternalModule_1.ts(4,9): error T
import Sammy = require('./exportAssignmentOfDeclaredExternalModule_0');
var x = new Sammy(); // error to use as constructor as there is not constructor symbol
~~~~~
!!! error TS2304: Cannot find name 'Sammy'.
!!! error TS2693: 'Sammy' only refers to a type, but is being used as a value here.
var y = Sammy(); // error to use interface name as call target
~~~~~
!!! error TS2304: Cannot find name 'Sammy'.
!!! error TS2693: 'Sammy' only refers to a type, but is being used as a value here.
var z: Sammy; // no error - z is of type interface Sammy from module 'M'
var a = new z(); // constructor - no error
var b = z(); // call signature - no error

View File

@ -1,4 +1,4 @@
tests/cases/compiler/genericConstructInvocationWithNoTypeArg.ts(4,27): error TS2304: Cannot find name 'Foo'.
tests/cases/compiler/genericConstructInvocationWithNoTypeArg.ts(4,27): error TS2693: 'Foo' only refers to a type, but is being used as a value here.
==== tests/cases/compiler/genericConstructInvocationWithNoTypeArg.ts (1 errors) ====
@ -7,5 +7,5 @@ tests/cases/compiler/genericConstructInvocationWithNoTypeArg.ts(4,27): error TS2
}
var f2: Foo<number> = new Foo(3);
~~~
!!! error TS2304: Cannot find name 'Foo'.
!!! error TS2693: 'Foo' only refers to a type, but is being used as a value here.

View File

@ -1,11 +1,11 @@
tests/cases/compiler/inheritFromGenericTypeParameter.ts(1,20): error TS2304: Cannot find name 'T'.
tests/cases/compiler/inheritFromGenericTypeParameter.ts(1,20): error TS2693: 'T' only refers to a type, but is being used as a value here.
tests/cases/compiler/inheritFromGenericTypeParameter.ts(2,24): error TS2312: An interface may only extend a class or another interface.
==== tests/cases/compiler/inheritFromGenericTypeParameter.ts (2 errors) ====
class C<T> extends T { }
~
!!! error TS2304: Cannot find name 'T'.
!!! error TS2693: 'T' only refers to a type, but is being used as a value here.
interface I<T> extends T { }
~
!!! error TS2312: An interface may only extend a class or another interface.

View File

@ -10,7 +10,7 @@ tests/cases/compiler/intTypeCheck.ts(103,5): error TS2322: Type '() => void' is
Property 'p' is missing in type '() => void'.
tests/cases/compiler/intTypeCheck.ts(106,5): error TS2322: Type 'boolean' is not assignable to type 'i1'.
tests/cases/compiler/intTypeCheck.ts(106,20): error TS1109: Expression expected.
tests/cases/compiler/intTypeCheck.ts(106,21): error TS2304: Cannot find name 'i1'.
tests/cases/compiler/intTypeCheck.ts(106,21): error TS2693: 'i1' only refers to a type, but is being used as a value here.
tests/cases/compiler/intTypeCheck.ts(107,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
tests/cases/compiler/intTypeCheck.ts(112,5): error TS2322: Type '{}' is not assignable to type 'i2'.
Type '{}' provides no match for the signature '(): any'
@ -21,7 +21,7 @@ tests/cases/compiler/intTypeCheck.ts(115,5): error TS2322: Type 'Base' is not as
Type 'Base' provides no match for the signature '(): any'
tests/cases/compiler/intTypeCheck.ts(120,5): error TS2322: Type 'boolean' is not assignable to type 'i2'.
tests/cases/compiler/intTypeCheck.ts(120,21): error TS1109: Expression expected.
tests/cases/compiler/intTypeCheck.ts(120,22): error TS2304: Cannot find name 'i2'.
tests/cases/compiler/intTypeCheck.ts(120,22): error TS2693: 'i2' only refers to a type, but is being used as a value here.
tests/cases/compiler/intTypeCheck.ts(121,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
tests/cases/compiler/intTypeCheck.ts(126,5): error TS2322: Type '{}' is not assignable to type 'i3'.
Type '{}' provides no match for the signature 'new (): any'
@ -33,12 +33,12 @@ tests/cases/compiler/intTypeCheck.ts(131,5): error TS2322: Type '() => void' is
Type '() => void' provides no match for the signature 'new (): any'
tests/cases/compiler/intTypeCheck.ts(134,5): error TS2322: Type 'boolean' is not assignable to type 'i3'.
tests/cases/compiler/intTypeCheck.ts(134,21): error TS1109: Expression expected.
tests/cases/compiler/intTypeCheck.ts(134,22): error TS2304: Cannot find name 'i3'.
tests/cases/compiler/intTypeCheck.ts(134,22): error TS2693: 'i3' only refers to a type, but is being used as a value here.
tests/cases/compiler/intTypeCheck.ts(135,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
tests/cases/compiler/intTypeCheck.ts(142,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
tests/cases/compiler/intTypeCheck.ts(148,5): error TS2322: Type 'boolean' is not assignable to type 'i4'.
tests/cases/compiler/intTypeCheck.ts(148,21): error TS1109: Expression expected.
tests/cases/compiler/intTypeCheck.ts(148,22): error TS2304: Cannot find name 'i4'.
tests/cases/compiler/intTypeCheck.ts(148,22): error TS2693: 'i4' only refers to a type, but is being used as a value here.
tests/cases/compiler/intTypeCheck.ts(149,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
tests/cases/compiler/intTypeCheck.ts(154,5): error TS2322: Type '{}' is not assignable to type 'i5'.
Property 'p' is missing in type '{}'.
@ -51,7 +51,7 @@ tests/cases/compiler/intTypeCheck.ts(159,5): error TS2322: Type '() => void' is
Property 'p' is missing in type '() => void'.
tests/cases/compiler/intTypeCheck.ts(162,5): error TS2322: Type 'boolean' is not assignable to type 'i5'.
tests/cases/compiler/intTypeCheck.ts(162,21): error TS1109: Expression expected.
tests/cases/compiler/intTypeCheck.ts(162,22): error TS2304: Cannot find name 'i5'.
tests/cases/compiler/intTypeCheck.ts(162,22): error TS2693: 'i5' only refers to a type, but is being used as a value here.
tests/cases/compiler/intTypeCheck.ts(163,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
tests/cases/compiler/intTypeCheck.ts(168,5): error TS2322: Type '{}' is not assignable to type 'i6'.
Type '{}' provides no match for the signature '(): any'
@ -64,7 +64,7 @@ tests/cases/compiler/intTypeCheck.ts(173,5): error TS2322: Type '() => void' is
Type 'void' is not assignable to type 'number'.
tests/cases/compiler/intTypeCheck.ts(176,5): error TS2322: Type 'boolean' is not assignable to type 'i6'.
tests/cases/compiler/intTypeCheck.ts(176,21): error TS1109: Expression expected.
tests/cases/compiler/intTypeCheck.ts(176,22): error TS2304: Cannot find name 'i6'.
tests/cases/compiler/intTypeCheck.ts(176,22): error TS2693: 'i6' only refers to a type, but is being used as a value here.
tests/cases/compiler/intTypeCheck.ts(177,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
tests/cases/compiler/intTypeCheck.ts(182,5): error TS2322: Type '{}' is not assignable to type 'i7'.
Type '{}' provides no match for the signature 'new (): any'
@ -76,12 +76,12 @@ tests/cases/compiler/intTypeCheck.ts(187,5): error TS2322: Type '() => void' is
Type '() => void' provides no match for the signature 'new (): any'
tests/cases/compiler/intTypeCheck.ts(190,5): error TS2322: Type 'boolean' is not assignable to type 'i7'.
tests/cases/compiler/intTypeCheck.ts(190,21): error TS1109: Expression expected.
tests/cases/compiler/intTypeCheck.ts(190,22): error TS2304: Cannot find name 'i7'.
tests/cases/compiler/intTypeCheck.ts(190,22): error TS2693: 'i7' only refers to a type, but is being used as a value here.
tests/cases/compiler/intTypeCheck.ts(191,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
tests/cases/compiler/intTypeCheck.ts(198,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
tests/cases/compiler/intTypeCheck.ts(204,5): error TS2322: Type 'boolean' is not assignable to type 'i8'.
tests/cases/compiler/intTypeCheck.ts(204,21): error TS1109: Expression expected.
tests/cases/compiler/intTypeCheck.ts(204,22): error TS2304: Cannot find name 'i8'.
tests/cases/compiler/intTypeCheck.ts(204,22): error TS2693: 'i8' only refers to a type, but is being used as a value here.
tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
@ -214,7 +214,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit
~
!!! error TS1109: Expression expected.
~~
!!! error TS2304: Cannot find name 'i1'.
!!! error TS2693: 'i1' only refers to a type, but is being used as a value here.
var obj10: i1 = new {};
~~~~~~
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
@ -247,7 +247,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit
~
!!! error TS1109: Expression expected.
~~
!!! error TS2304: Cannot find name 'i2'.
!!! error TS2693: 'i2' only refers to a type, but is being used as a value here.
var obj21: i2 = new {};
~~~~~~
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
@ -281,7 +281,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit
~
!!! error TS1109: Expression expected.
~~
!!! error TS2304: Cannot find name 'i3'.
!!! error TS2693: 'i3' only refers to a type, but is being used as a value here.
var obj32: i3 = new {};
~~~~~~
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
@ -305,7 +305,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit
~
!!! error TS1109: Expression expected.
~~
!!! error TS2304: Cannot find name 'i4'.
!!! error TS2693: 'i4' only refers to a type, but is being used as a value here.
var obj43: i4 = new {};
~~~~~~
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
@ -341,7 +341,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit
~
!!! error TS1109: Expression expected.
~~
!!! error TS2304: Cannot find name 'i5'.
!!! error TS2693: 'i5' only refers to a type, but is being used as a value here.
var obj54: i5 = new {};
~~~~~~
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
@ -377,7 +377,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit
~
!!! error TS1109: Expression expected.
~~
!!! error TS2304: Cannot find name 'i6'.
!!! error TS2693: 'i6' only refers to a type, but is being used as a value here.
var obj65: i6 = new {};
~~~~~~
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
@ -411,7 +411,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit
~
!!! error TS1109: Expression expected.
~~
!!! error TS2304: Cannot find name 'i7'.
!!! error TS2693: 'i7' only refers to a type, but is being used as a value here.
var obj76: i7 = new {};
~~~~~~
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
@ -435,7 +435,7 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit
~
!!! error TS1109: Expression expected.
~~
!!! error TS2304: Cannot find name 'i8'.
!!! error TS2693: 'i8' only refers to a type, but is being used as a value here.
var obj87: i8 = new {};
~~~~~~
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.

View File

@ -1,4 +1,4 @@
tests/cases/compiler/interfaceNameAsIdentifier.ts(4,1): error TS2304: Cannot find name 'C'.
tests/cases/compiler/interfaceNameAsIdentifier.ts(4,1): error TS2693: 'C' only refers to a type, but is being used as a value here.
tests/cases/compiler/interfaceNameAsIdentifier.ts(12,1): error TS2304: Cannot find name 'm2'.
@ -8,7 +8,7 @@ tests/cases/compiler/interfaceNameAsIdentifier.ts(12,1): error TS2304: Cannot fi
}
C();
~
!!! error TS2304: Cannot find name 'C'.
!!! error TS2693: 'C' only refers to a type, but is being used as a value here.
module m2 {
export interface C {

View File

@ -1,19 +1,19 @@
tests/cases/compiler/interfaceNaming1.ts(1,1): error TS2304: Cannot find name 'interface'.
tests/cases/compiler/interfaceNaming1.ts(1,1): error TS2693: 'interface' only refers to a type, but is being used as a value here.
tests/cases/compiler/interfaceNaming1.ts(1,11): error TS1005: ';' expected.
tests/cases/compiler/interfaceNaming1.ts(3,1): error TS2304: Cannot find name 'interface'.
tests/cases/compiler/interfaceNaming1.ts(3,1): error TS2693: 'interface' only refers to a type, but is being used as a value here.
tests/cases/compiler/interfaceNaming1.ts(3,13): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
==== tests/cases/compiler/interfaceNaming1.ts (4 errors) ====
interface { }
~~~~~~~~~
!!! error TS2304: Cannot find name 'interface'.
!!! error TS2693: 'interface' only refers to a type, but is being used as a value here.
~
!!! error TS1005: ';' expected.
interface interface{ }
interface & { }
~~~~~~~~~
!!! error TS2304: Cannot find name 'interface'.
!!! error TS2693: 'interface' only refers to a type, but is being used as a value here.
~~~
!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.

View File

@ -1,6 +1,6 @@
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(23,12): error TS2503: Cannot find namespace 'I'.
tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(23,12): error TS2693: 'I' only refers to a type, but is being used as a value here.
==== tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts (3 errors) ====
@ -32,5 +32,5 @@ tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIde
import i = I;
~
!!! error TS2503: Cannot find namespace 'I'.
!!! error TS2693: 'I' only refers to a type, but is being used as a value here.

View File

@ -1,7 +1,7 @@
tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(4,1): error TS2364: Invalid left-hand side of assignment expression.
tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property.
tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(9,1): error TS2364: Invalid left-hand side of assignment expression.
tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(14,1): error TS2304: Cannot find name 'I'.
tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(14,1): error TS2693: 'I' only refers to a type, but is being used as a value here.
tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(17,1): error TS2364: Invalid left-hand side of assignment expression.
tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.ts(21,1): error TS2364: Invalid left-hand side of assignment expression.
@ -28,7 +28,7 @@ tests/cases/conformance/types/primitives/undefined/invalidUndefinedAssignments.t
g = x;
I = x;
~
!!! error TS2304: Cannot find name 'I'.
!!! error TS2693: 'I' only refers to a type, but is being used as a value here.
module M { export var x = 1; }
M = x;

View File

@ -1,7 +1,7 @@
error TS2318: Cannot find global type 'Boolean'.
error TS2318: Cannot find global type 'IArguments'.
error TS2318: Cannot find global type 'Number'.
tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib.ts(4,12): error TS2304: Cannot find name 'Array'.
tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib.ts(4,12): error TS2693: 'Array' only refers to a type, but is being used as a value here.
!!! error TS2318: Cannot find global type 'Boolean'.
@ -13,7 +13,7 @@ tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib
function f(x: number, y: number, z: number) {
return Array.from(arguments);
~~~~~
!!! error TS2304: Cannot find name 'Array'.
!!! error TS2693: 'Array' only refers to a type, but is being used as a value here.
}
f(1, 2, 3);

View File

@ -1,4 +1,4 @@
tests/cases/compiler/newOperator.ts(3,13): error TS2304: Cannot find name 'ifc'.
tests/cases/compiler/newOperator.ts(3,13): error TS2693: 'ifc' only refers to a type, but is being used as a value here.
tests/cases/compiler/newOperator.ts(10,10): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
tests/cases/compiler/newOperator.ts(11,10): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
tests/cases/compiler/newOperator.ts(12,5): error TS2304: Cannot find name 'string'.
@ -17,7 +17,7 @@ tests/cases/compiler/newOperator.ts(45,23): error TS1150: 'new T[]' cannot be us
// Attempting to 'new' an interface yields poor error
var i = new ifc();
~~~
!!! error TS2304: Cannot find name 'ifc'.
!!! error TS2693: 'ifc' only refers to a type, but is being used as a value here.
// Parens are optional
var x = new Date;

View File

@ -5,7 +5,7 @@ tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(5,6): error
tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,1): error TS2304: Cannot find name 'type'.
tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,6): error TS1005: ';' expected.
tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,11): error TS1109: Expression expected.
tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,13): error TS2304: Cannot find name 'I'.
tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,13): error TS2693: 'I' only refers to a type, but is being used as a value here.
==== tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts (8 errors) ====
@ -30,4 +30,4 @@ tests/cases/conformance/types/typeAliases/reservedNamesInAliases.ts(6,13): error
~
!!! error TS1109: Expression expected.
~
!!! error TS2304: Cannot find name 'I'.
!!! error TS2693: 'I' only refers to a type, but is being used as a value here.

View File

@ -1,5 +1,5 @@
tests/cases/compiler/returnTypeParameter.ts(1,22): error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.
tests/cases/compiler/returnTypeParameter.ts(2,34): error TS2304: Cannot find name 'T'.
tests/cases/compiler/returnTypeParameter.ts(2,34): error TS2693: 'T' only refers to a type, but is being used as a value here.
==== tests/cases/compiler/returnTypeParameter.ts (2 errors) ====
@ -8,4 +8,4 @@ tests/cases/compiler/returnTypeParameter.ts(2,34): error TS2304: Cannot find nam
!!! error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.
function f2<T>(a: T): T { return T; } // bug was that this satisfied the return statement requirement
~
!!! error TS2304: Cannot find name 'T'.
!!! error TS2693: 'T' only refers to a type, but is being used as a value here.

View File

@ -16,9 +16,9 @@ tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(21,9): error TS
tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(21,17): error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode.
tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(23,20): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode.
tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(25,20): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode.
tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(25,20): error TS2503: Cannot find namespace 'public'.
tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(25,20): error TS2693: 'public' only refers to a type, but is being used as a value here.
tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(26,21): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode.
tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(26,21): error TS2503: Cannot find namespace 'public'.
tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(26,21): error TS2693: 'public' only refers to a type, but is being used as a value here.
tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(27,17): error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode.
tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(27,17): error TS2304: Cannot find name 'package'.
tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(28,17): error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode.
@ -88,12 +88,12 @@ tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(28,17): error T
~~~~~~
!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode.
~~~~~~
!!! error TS2503: Cannot find namespace 'public'.
!!! error TS2693: 'public' only refers to a type, but is being used as a value here.
class F1 implements public.private.implements { }
~~~~~~
!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode.
~~~~~~
!!! error TS2503: Cannot find namespace 'public'.
!!! error TS2693: 'public' only refers to a type, but is being used as a value here.
class G extends package { }
~~~~~~~
!!! error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode.

View File

@ -1,11 +1,11 @@
tests/cases/compiler/typeParameterAsBaseClass.ts(1,20): error TS2304: Cannot find name 'T'.
tests/cases/compiler/typeParameterAsBaseClass.ts(1,20): error TS2693: 'T' only refers to a type, but is being used as a value here.
tests/cases/compiler/typeParameterAsBaseClass.ts(2,24): error TS2422: A class may only implement another class or interface.
==== tests/cases/compiler/typeParameterAsBaseClass.ts (2 errors) ====
class C<T> extends T {}
~
!!! error TS2304: Cannot find name 'T'.
!!! error TS2693: 'T' only refers to a type, but is being used as a value here.
class C2<T> implements T {}
~
!!! error TS2422: A class may only implement another class or interface.

View File

@ -1,5 +1,5 @@
tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(4,20): error TS2304: Cannot find name 'T'.
tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(5,24): error TS2304: Cannot find name 'U'.
tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(4,20): error TS2693: 'T' only refers to a type, but is being used as a value here.
tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(5,24): error TS2693: 'U' only refers to a type, but is being used as a value here.
tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(7,24): error TS2312: An interface may only extend a class or another interface.
tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(8,28): error TS2312: An interface may only extend a class or another interface.
@ -10,10 +10,10 @@ tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(8,28): e
class C<T> extends T { }
~
!!! error TS2304: Cannot find name 'T'.
!!! error TS2693: 'T' only refers to a type, but is being used as a value here.
class C2<T, U> extends U { }
~
!!! error TS2304: Cannot find name 'U'.
!!! error TS2693: 'U' only refers to a type, but is being used as a value here.
interface I<T> extends T { }
~

View File

@ -0,0 +1,50 @@
tests/cases/compiler/typeUsedAsValueError.ts(16,11): error TS2693: 'Interface' only refers to a type, but is being used as a value here.
tests/cases/compiler/typeUsedAsValueError.ts(17,11): error TS2304: Cannot find name 'InterfaceNotFound'.
tests/cases/compiler/typeUsedAsValueError.ts(18,13): error TS2693: 'TypeAliasForSomeClass' only refers to a type, but is being used as a value here.
tests/cases/compiler/typeUsedAsValueError.ts(19,16): error TS2693: 'TypeAliasForSomeClass' only refers to a type, but is being used as a value here.
tests/cases/compiler/typeUsedAsValueError.ts(20,16): error TS2304: Cannot find name 'TypeAliasForSomeClassNotFound'.
tests/cases/compiler/typeUsedAsValueError.ts(21,11): error TS2693: 'someType' only refers to a type, but is being used as a value here.
tests/cases/compiler/typeUsedAsValueError.ts(22,17): error TS2693: 'someType' only refers to a type, but is being used as a value here.
tests/cases/compiler/typeUsedAsValueError.ts(23,17): error TS2304: Cannot find name 'someTypeNotFound'.
==== tests/cases/compiler/typeUsedAsValueError.ts (8 errors) ====
interface Interface {
}
class SomeClass {
}
type TypeAliasForSomeClass = SomeClass;
type someType = { x: number };
function acceptsSomeType(a: someType) {
}
let one = Interface;
~~~~~~~~~
!!! error TS2693: 'Interface' only refers to a type, but is being used as a value here.
let two = InterfaceNotFound;
~~~~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'InterfaceNotFound'.
let three = TypeAliasForSomeClass;
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2693: 'TypeAliasForSomeClass' only refers to a type, but is being used as a value here.
let four = new TypeAliasForSomeClass();
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2693: 'TypeAliasForSomeClass' only refers to a type, but is being used as a value here.
let five = new TypeAliasForSomeClassNotFound();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'TypeAliasForSomeClassNotFound'.
let six = someType;
~~~~~~~~
!!! error TS2693: 'someType' only refers to a type, but is being used as a value here.
acceptsSomeType(someType);
~~~~~~~~
!!! error TS2693: 'someType' only refers to a type, but is being used as a value here.
acceptsSomeType(someTypeNotFound);
~~~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'someTypeNotFound'.

View File

@ -0,0 +1,41 @@
//// [typeUsedAsValueError.ts]
interface Interface {
}
class SomeClass {
}
type TypeAliasForSomeClass = SomeClass;
type someType = { x: number };
function acceptsSomeType(a: someType) {
}
let one = Interface;
let two = InterfaceNotFound;
let three = TypeAliasForSomeClass;
let four = new TypeAliasForSomeClass();
let five = new TypeAliasForSomeClassNotFound();
let six = someType;
acceptsSomeType(someType);
acceptsSomeType(someTypeNotFound);
//// [typeUsedAsValueError.js]
var SomeClass = (function () {
function SomeClass() {
}
return SomeClass;
}());
function acceptsSomeType(a) {
}
var one = Interface;
var two = InterfaceNotFound;
var three = TypeAliasForSomeClass;
var four = new TypeAliasForSomeClass();
var five = new TypeAliasForSomeClassNotFound();
var six = someType;
acceptsSomeType(someType);
acceptsSomeType(someTypeNotFound);

View File

@ -0,0 +1,28 @@
tests/cases/compiler/world.ts(4,1): error TS2693: 'HelloInterface' only refers to a type, but is being used as a value here.
tests/cases/compiler/world.ts(5,1): error TS2304: Cannot find name 'HelloNamespace'.
==== tests/cases/compiler/world.ts (2 errors) ====
import HelloInterface = require("helloInterface");
import HelloNamespace = require("helloNamespace");
HelloInterface.world;
~~~~~~~~~~~~~~
!!! error TS2693: 'HelloInterface' only refers to a type, but is being used as a value here.
HelloNamespace.world;
~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'HelloNamespace'.
==== tests/cases/compiler/helloInterface.ts (0 errors) ====
interface HelloInterface {
world: any;
}
export = HelloInterface;
==== tests/cases/compiler/helloNamespace.ts (0 errors) ====
namespace HelloNamespace {
export type world = any;
}
export = HelloNamespace;

View File

@ -0,0 +1,37 @@
//// [tests/cases/compiler/typeUsedAsValueError2.ts] ////
//// [helloInterface.ts]
interface HelloInterface {
world: any;
}
export = HelloInterface;
//// [helloNamespace.ts]
namespace HelloNamespace {
export type world = any;
}
export = HelloNamespace;
//// [world.ts]
import HelloInterface = require("helloInterface");
import HelloNamespace = require("helloNamespace");
HelloInterface.world;
HelloNamespace.world;
//// [helloInterface.js]
define(["require", "exports"], function (require, exports) {
"use strict";
});
//// [helloNamespace.js]
define(["require", "exports"], function (require, exports) {
"use strict";
});
//// [world.js]
define(["require", "exports"], function (require, exports) {
"use strict";
HelloInterface.world;
HelloNamespace.world;
});

View File

@ -1,5 +1,5 @@
tests/cases/compiler/typeofSimple.ts(3,5): error TS2322: Type 'number' is not assignable to type 'string'.
tests/cases/compiler/typeofSimple.ts(8,21): error TS2304: Cannot find name 'J'.
tests/cases/compiler/typeofSimple.ts(8,21): error TS2693: 'J' only refers to a type, but is being used as a value here.
==== tests/cases/compiler/typeofSimple.ts (2 errors) ====
@ -14,7 +14,7 @@ tests/cases/compiler/typeofSimple.ts(8,21): error TS2304: Cannot find name 'J'.
var numberJ: typeof J; //Error, cannot reference type in typeof
~
!!! error TS2304: Cannot find name 'J'.
!!! error TS2693: 'J' only refers to a type, but is being used as a value here.
var numberI: I<typeof v2>;
var fun: () => I<number>;

View File

@ -1,4 +1,4 @@
tests/cases/conformance/types/specifyingTypes/typeQueries/typeofTypeParameter.ts(3,19): error TS2304: Cannot find name 'T'.
tests/cases/conformance/types/specifyingTypes/typeQueries/typeofTypeParameter.ts(3,19): error TS2693: 'T' only refers to a type, but is being used as a value here.
==== tests/cases/conformance/types/specifyingTypes/typeQueries/typeofTypeParameter.ts (1 errors) ====
@ -6,6 +6,6 @@ tests/cases/conformance/types/specifyingTypes/typeQueries/typeofTypeParameter.ts
var a: typeof x;
var y: typeof T;
~
!!! error TS2304: Cannot find name 'T'.
!!! error TS2693: 'T' only refers to a type, but is being used as a value here.
return a;
}

View File

@ -1,6 +1,6 @@
tests/cases/conformance/types/primitives/null/validNullAssignments.ts(10,1): error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property.
tests/cases/conformance/types/primitives/null/validNullAssignments.ts(15,1): error TS2364: Invalid left-hand side of assignment expression.
tests/cases/conformance/types/primitives/null/validNullAssignments.ts(20,1): error TS2304: Cannot find name 'I'.
tests/cases/conformance/types/primitives/null/validNullAssignments.ts(20,1): error TS2693: 'I' only refers to a type, but is being used as a value here.
tests/cases/conformance/types/primitives/null/validNullAssignments.ts(23,1): error TS2364: Invalid left-hand side of assignment expression.
tests/cases/conformance/types/primitives/null/validNullAssignments.ts(30,1): error TS2364: Invalid left-hand side of assignment expression.
@ -31,7 +31,7 @@ tests/cases/conformance/types/primitives/null/validNullAssignments.ts(30,1): err
g = null; // ok
I = null; // error
~
!!! error TS2304: Cannot find name 'I'.
!!! error TS2693: 'I' only refers to a type, but is being used as a value here.
module M { export var x = 1; }
M = null; // error

View File

@ -0,0 +1,23 @@
interface Interface {
}
class SomeClass {
}
type TypeAliasForSomeClass = SomeClass;
type someType = { x: number };
function acceptsSomeType(a: someType) {
}
let one = Interface;
let two = InterfaceNotFound;
let three = TypeAliasForSomeClass;
let four = new TypeAliasForSomeClass();
let five = new TypeAliasForSomeClassNotFound();
let six = someType;
acceptsSomeType(someType);
acceptsSomeType(someTypeNotFound);

View File

@ -0,0 +1,21 @@
// @module: amd
// @filename: helloInterface.ts
interface HelloInterface {
world: any;
}
export = HelloInterface;
// @filename: helloNamespace.ts
namespace HelloNamespace {
export type world = any;
}
export = HelloNamespace;
// @filename: world.ts
import HelloInterface = require("helloInterface");
import HelloNamespace = require("helloNamespace");
HelloInterface.world;
HelloNamespace.world;