1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
=== tests/cases/conformance/classes/propertyMemberDeclarations/constructorParameterShadowsOuterScopes.ts ===
// 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;
>x : Symbol(x, Decl(constructorParameterShadowsOuterScopes.ts, 5, 3))
class C {
>C : Symbol(C, Decl(constructorParameterShadowsOuterScopes.ts, 5, 10))
b = x; // error, evaluated in scope of constructor, cannot reference x
>b : Symbol(C.b, Decl(constructorParameterShadowsOuterScopes.ts, 6, 9))
constructor(x: string) {
>x : Symbol(x, Decl(constructorParameterShadowsOuterScopes.ts, 8, 16))
x = 2; // error, x is string
>x : Symbol(x, Decl(constructorParameterShadowsOuterScopes.ts, 8, 16))
}
}
var y = 1;
>y : Symbol(y, Decl(constructorParameterShadowsOuterScopes.ts, 13, 3))
class D {
>D : Symbol(D, Decl(constructorParameterShadowsOuterScopes.ts, 13, 10))
b = y; // error, evaluated in scope of constructor, cannot reference y
>b : Symbol(D.b, Decl(constructorParameterShadowsOuterScopes.ts, 14, 9))
constructor(x: string) {
>x : Symbol(x, Decl(constructorParameterShadowsOuterScopes.ts, 16, 16))
var y = "";
>y : Symbol(y, Decl(constructorParameterShadowsOuterScopes.ts, 17, 11))
}
}
|