Disjoint union refinement doesn't work with Date type
- Vorherrschende Sprache
- Rust
- Sterne
- 22.3k
- Forks
- 1.9k
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.