flow icon indicating copy to clipboard operation
flow copied to clipboard

Non initialize class fields doesn't treats as nullable

Open Renegatto opened this issue 4 years ago • 0 comments

Flow version: 0.144.0

Followed code are invalid at the type level, but it successfully typechecks by Flow:

/* @flow */
class Foo { foo : string } //field 'foo' has no initializer but have type 'string'
const my_foo : Foo = new Foo()
const undefined_here : string = my_foo.foo // 'undefined_here' type was declared as 'string'
                                           // but it's value will be 'undefined'

Expected behavior

Static checking time error.

Actual behavior

Successfully passed typechecking, and undefined at the runtime.

Reproducing:

at the flow.org/try

Renegatto avatar Feb 16 '21 18:02 Renegatto