1. 7
    1. 2

      The biggest complaint about Flow internally at Meta was performance… until they shipped the equivalent of isolated declarations (so inference had to cross module boundaries much less often). I think this feature is going to be a big deal further down the road.

      The type predicate inference is super welcome too. I’m excited for this release!

      1. 2

        The Inferred Type Predicates is incredibly useful, most notably for Array#filter as indicated in TFA.

        However I wonder if this can be extended to have “checked predicates”. Often times I have a function like

        interface Dict {
        	dict: Record<string, string>,
        }
        interface List {
        	list: string[],
        }
        type Value = Dict | List;
        
        function isDict(v: Value): v is Dict {
        	return "dict" in v;
        }
        

        But the problem is that any predicate function is effectively unsafe because TypeScript just assumes the returned value is correct. Maybe someone refactors Value to be

        interface Dict {
        	kind: "dict",
        	items: Record<string, string>,
        }
        interface List {
        	kind: "list",
        	items: string[],
        }
        type Value = Dict | List;
        

        They forgot to update isDict but it still compiles! It would be great if you could do something like v checked is Dict or something. In many cases the helper is provable, so you don’t need the unsafe behaviour. (Of course you still do need the unsafe behaviour in some cases, I’m not saying that the old form should be removed.) It seems like with this update you could let the compiler infer the type of isDict, but then you may end up with worse error messages where type inference points the error at the wrong location.