[react-loadable] Make type application of ReactLoadable.Map more precisely #2934
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why
When a programmer uses Loadable.Map, he faces a situation where a loaded module hasn't any type-restriction.
(Actually, it may evaluate as
empty
)Then, the programmer applies its own type arguments into
Loadable.Map
like below.But this application causes type error with a message like
Cannot instantiate
MapOptionsbecause number [1] is incompatible with string [2] in property
bof type argument
Loadable.Map.
.This causes from a restriction of type argument named
TModules
.It defined as
MapOptions<TProps, TModules: { [key: string]: * }>
,When type arguments applied to TModules, It seems Flow may infer resctriction of TModules like
{[string]: () => Promise<string> & () => Promise<number>}
, of course actual value like this can't exist anyay.Therefore, it would be better to relax restriction of TModules to a type of properties as covariant.
It makes Flow can infer TModules more pragmatically.
FYI: A situation described above can reproduce more simply as below.
Try code.