TypeScript/tests/baselines/reference/constructorParameterShadowsOuterScopes.errors.txt

32 lines
1.9 KiB
Plaintext
Raw Normal View History

tests/cases/conformance/classes/propertyMemberDeclarations/constructorParameterShadowsOuterScopes.ts(8,9): error TS2301: Initializer of instance member variable 'b' cannot reference identifier 'x' declared in the constructor.
2014-11-05 21:26:03 +01:00
tests/cases/conformance/classes/propertyMemberDeclarations/constructorParameterShadowsOuterScopes.ts(10,9): error TS2322: Type 'number' is not assignable to type 'string'.
tests/cases/conformance/classes/propertyMemberDeclarations/constructorParameterShadowsOuterScopes.ts(16,9): error TS2301: Initializer of instance member variable 'b' cannot reference identifier 'y' declared in the constructor.
2014-07-13 01:04:16 +02:00
==== tests/cases/conformance/classes/propertyMemberDeclarations/constructorParameterShadowsOuterScopes.ts (3 errors) ====
// Initializer expressions for instance member variables are evaluated in the scope of the class constructor
// body but are not permitted to reference parameters or local variables of the constructor.
// This effectively means that entities from outer scopes by the same name as a constructor parameter or
// local variable are inaccessible in initializer expressions for instance member variables
var x = 1;
class C {
b = x; // error, evaluated in scope of constructor, cannot reference x
~
!!! error TS2301: Initializer of instance member variable 'b' cannot reference identifier 'x' declared in the constructor.
2014-07-13 01:04:16 +02:00
constructor(x: string) {
x = 2; // error, x is string
~
2014-11-05 21:26:03 +01:00
!!! error TS2322: Type 'number' is not assignable to type 'string'.
2014-07-13 01:04:16 +02:00
}
}
var y = 1;
class D {
b = y; // error, evaluated in scope of constructor, cannot reference y
~
!!! error TS2301: Initializer of instance member variable 'b' cannot reference identifier 'y' declared in the constructor.
2014-07-13 01:04:16 +02:00
constructor(x: string) {
var y = "";
}
}