facebook / facebook/flow

Strange behaviour when variable is inited with null

Aperta
#3,802 3 commenti 1 reazione 0 assegnatari Vedi su GitHub
Lingua principale
Rust
Stelle
22.3k
Fork
1.9k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Hi!

I've got a test, that looks like this

```js
declare function it(name: string, fn: any): void;
declare function describe(fn: any): void;
declare function beforeEach(fn: any): void;

declare function f(): {prop: string};

describe(() => {
let result = null;

beforeEach(() => {
result = f();
});

it('some test', () => {
result.prop;
});
});
```

I've got some function `f()` that always returns some value that is not a null, but I init `result` variable with null value. Flow shows me an error on this test:

```
15: result.prop;
^ property `prop`. Property cannot be accessed on possibly null value
15: result.prop;
^ null
```

The error disappears if I change `let result = null;` to `let result;`. ([Here](https://flow.org/try/#0CYUwxgNghgTiAEAzArgOzAFwJYHtXywwApUoBbEALngGcMYtUBzAGiVWqlQE8BKagG44swANwAoUJFgIU6bHnigaYBgCMQRRB3hc+g4WMnhocJGky58GxDjgBRKGAAWWnXv7whIicelm5S0VEIk8AbwAHGBwI6joGZgBfX2VVLA0iUPgAXgA+eDDxeHgIEAx4OBpkCHLs+FRqiAliovgbOxBHF0zeHPzC4uLK6tqkUOb4RN4J1sIiAHIaHAp4DBA6ebYsvILWofWRgDoomImpiXOgA) is an example in Flow REPL)

Is it an expected behaviour or a bug?

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.