facebook / facebook/flow

Disjoint union refinement doesn't work with Date type

Aperta
#4,593 1 commento 0 reazioni 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

I was doing Date refinement following the official [docs](https://flow.org/en/docs/types/unions/#disjoint-unions-with-exact-types-a-classtoc-idtoc-disjoint-unions-with-exact-types-hreftoc-disjoint-unions-with-exact-typesa) and excepted that no error message will be thrown

```
// This is from official docs
type Success = {| success: true, value: boolean |};
type Failed = {| error: true, message: string |};

type Response = Success | Failed;

function handleResponse(response: Response) {
if (response.success) {
var value: boolean = response.value;
} else {
var message: string = response.message;
}
}

// Here is for Date type

type dateParts = {| day?: string, month?: string, year?: string |};

type dateOrObject = dateParts | Date;
const value: dateOrObject = { year: '2017'};
if (value.year) { // does not work
const { day, month, year } = value;
}
if (! (value instanceof Date)) { // works
const { day, month, year } = value;
}
```

Here is the [reproduction](https://flow.org/try/#0PTAEBUAsEsGdTqAZgJwPYFtRqU6BjaAQwBtQATNfWAKABcBPABwFNQBlAV33xdngC8oAN4AfULG69+ALlB0UnFgBpQAN1JK5AIzRoSLIgDtQogL4BueszYAxItAPlQoIWNAsU6FHIVLVGHywRADmLHKwCtBGIaaWNNasoABKfExoRrBsQlw8Qaag9o4s5FY0SJxG+HTQGaCQxuQGqbDpmSwAFChpGVlyLW1ZAJQiNC7QSKBdPe0AdJJ5-CPCYy7qRCjrJFqguvqGJkLdrb0ssxrbLFYuZh4kWaNr65uB-KHhElExrqDHg2evYJha6gMw0ME0ECgAASnjYiCQaE2ABEiHQ2IxWAlMWxyGiWAAFDZ0QQicR4hgAfgiXxCAQydEg1M+KGidNADEMKGZkVZ33MZRxFHxAHkUCLtAArFjVH549FElAkgqo9FWfC9OhbHbylhiiXS2VuDlcuQAcgATAAGACMAHYzfEJlMLkpZpyNstQFDKHxQEY0FqAO5IgDWqw1mS1wmFDHpRkZqg9m1uQldV3BNGdHQAhC7NPCo8ZeDhQKqWEMvVCQyhQ7QXJHIiJY-HEyaNqCfumrGYgA)

Ei

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.