flowjs / flow.js

A JavaScript library providing multiple simultaneous, stable, fault-tolerant and resumable/restartable file uploads via the HTML5 File API.
Other
2.96k stars 346 forks source link

Subtypes not unifying through generic parameter #355

Closed eborden closed 2 years ago

eborden commented 2 years ago

Maybe I'm missing something, but it seems that flow should be able to unify broken since Struct<string> is a subtype of Struct<Union>.

/* @flow */

type Union = number | string | boolean

type Struct<A> = {foo: A}

function unifies<A: Union>(x: Struct<A>) { }

function broken(x: Struct<Union>) { }

const struct:Struct<string> = {foo: "foo"}

unifies(struct)
broken(struct)

https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoVAXAngBwKZgCqAdgJZzFgC8YxArgLYBGeATmAD5gDOGrpxAOacwTOHBh4AhsXTZ8YAMp86AYwwAeAIIA+amADeUcQC4wWgL7oodYuvKVbpKKTzdtZkg50AKAB5myqxqmroAlIZgVqg2dhgOoqxwANZ4xP6BKuoaXhQ6EQZR6KoUvDxZGCZBIRq8-EJ6NEamYABExnCt0U4ubj51IWGoTEmp6QPqYUA