From 82fd5a884dbd4d058736981635198ba27e4d656d Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 18 Nov 2017 11:42:56 -0800 Subject: [PATCH] Add test --- .../strictPropertyInitialization.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/strictPropertyInitialization.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/strictPropertyInitialization.ts index 9c8d56e1f5a..01177200429 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/strictPropertyInitialization.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/strictPropertyInitialization.ts @@ -84,3 +84,18 @@ abstract class C9 { abstract c: number | null; abstract d?: number; } + +// Properties with non-undefined types must be assigned before they can be accessed +// within their constructor + +class C10 { + a: number; + b: number; + c?: number; + constructor() { + let x = this.a; // Error + this.a = this.b; // Error + this.b = x; + let y = this.c; + } +}