Closed
Description
Is this a bug or by design?
Environment
- TypeScript
- 2.1.0-dev.20160715
- 2.0.0
Steps to reproduce
compile the following code with tsc --strictNullChecks test.ts
:
// test.ts
class A {
a: Array<number>;
constructor() {}
}
var a = new A();
// this would be the error which is like "Cannot read property 'length' of undefined"
// because `a.a` is not uninitialized in A's constructor.
a.a.length;
Expected behavior
- I'd like to this should be a compile error by following reasons:
A.a
is not "nullable" (null
orundefined
) nor optional class propertya?
- But
A.a
is not initialized inA
'sconstructor
.
Actual behavior
- TypeScript compiler successes the compilation without any errors.
- I think this might be a pitfall.