flow strict should allow unclear types for generics
ayroblu opened this issue · 6 comments
Proposal
With the removal of inexact types for generics matching exact types in the recent versions, we should have an easy way to specify Function, Object types in Generics while in @flow strict
type Gen<T: Object> = ...
Use case
We use @flow strict
to reduce the usages of any types. However, for generics, we want to say that something is struct Object
. Before we would just use {}
(or {...}
) but that's now gone, we would like a way to say something is an Object without receiving the wrath of the checker that we're doing something wrong
Before we would just use {} (or {...}) but that's now gone
What do you mean by this? {...}
is a good upper bound for all objects, if you want to include interfaces as well as objects, you can use interface {}
This page contains information you can find to specify the top types: https://flow.org/en/docs/lang/type-hierarchy/
Arrays are invariantly typed, so you need to use $ReadOnlyArray
instead
For functions parameters, you will need contra-variance -
. Note that ({...}) => mixed
doesn't admit ({foo: string}) => mixed
, since a function that calls f: ({...}) => mixed
cannot be passed a callback that can only handle {foo: string}
objects.
The unclear-type
error is there because these types are just any, which is inherently unsafe. It's conceptually the same as this lint rules, except that it's built in the checker itself. If you are unhappy with it, you can disable the lint